我一直在试图找出如何删除.change()jquery处理程序,但没有运气。当选中单选按钮时,我正在使用它来激活某些表单字段,但是我不希望它为以后的每次更改触发。
$('.radio').change(function(){
alert("changed");
$('.fields').removeAttr('disabled');
//this is where I try removing the change handler
$(this).off('change');
});
Run Code Online (Sandbox Code Playgroud)
更改
// 'this' only removing the handler from the radio button that was changed
$(this).off('change');
Run Code Online (Sandbox Code Playgroud)
至
// removing the handler of all radio button
$('.radio').off('change');
Run Code Online (Sandbox Code Playgroud)
您的代码
$('.radio').change(function(){
alert("changed");
$('.fields').removeAttr('disabled');
$('.radio').off('change');
});
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/q5jqqgnt/3/
| 归档时间: |
|
| 查看次数: |
8963 次 |
| 最近记录: |