jquery代码如下所示。第一次,当我在#statement
的textarea中输入任何内容时,#checkbox
的相应复选框在屏幕上显示为选中的完美。
然后,当我清除#statement
的textarea时,#checkbox
的相应复选框在屏幕上显示为未选中--到目前为止还不错。
但是,当我继续键入#statement
的textarea时,#checkbox
的相应复选框并没有显示在屏幕上选中--不太好。
$('#statement').bind('input propertychange', function() {
if ($('#statement').val() != '') $('#checkbox').attr('checked', true);
else $('#checkbox').attr('checked', false);
}); // end .bind()
发布于 2014-05-31 11:03:07
我也面临着同样的问题。你只需要用道具而不是阿塔尔。以下是如何
$('#statement').bind('input propertychange', function() {
if ($('#statement').val() != '') $('#checkbox').prop('checked', true);
else $('#checkbox').removeProp('checked');
}); // end .bind()
发布于 2014-05-31 11:15:19
还可以使用keyup事件,如下所示:
$('#statement').keyup( function(){
if( $('#statement').val().length > 0 )
$("#checkbox").prop('checked' , 'keyup' );
else
$("#checkbox").removeProp( 'checked' );
});
https://stackoverflow.com/questions/23969260
复制相似问题