我需要在我的代码中禁用和启用一个 div - 我找到了用于禁用事件的 off() 和 on() 函数,它们工作正常,但问题是我无法使用我之前定义的处理程序。例如 :
这是在加载时禁用侦听器的代码
function disableEvent ()
{
$("body").ready(function(e)
{
$("#part *").attr("disabled","true").off("click");
$("#sgmnt *").attr("disabled","true").off("click");
$("#subSgmnt *").attr("disabled","true").off("click");
});
}
这是代码启用监听器
function enableElmnt ( id )
{
p="#"+id+" *";
alert(id);
$("body").ready(function(e) {
$(p).attr("disabled","false").on("click",false);
});
}
这是处理程序代码
$(document).ready(function() {
$(".partElements").not("#part19").not("#part20").not("#part21").click( function(){
$(".partElements").not("#part19").not("#part20").not("#part21").css("background-color","#FFF");
$(".partElements").not("#part19").not("#part20").not("#part21").css("color","#000");
$(this).css("background-color","#000");
$(this).css("color","#FFF");
selectDiv=$(this).attr("id");
loadLists("2",selectDiv);
});
});
和html代码
<div id="part">
<div class="partElements" id="part1"></div>
<div class="partElements" id="part2"></div>
<div class="partElements" id="part3"></div>
<div class="partElements" id="part4"></div>
<div class="partElements" id="part5"></div>
<div class="partElements" id="part6"></div>
<div class="partElements" id="part7"></div>
<div class="partElements" id="part8"></div>
<div class="partElements" id="part9"></div>
<div class="partElements" id="part10"></div>
<div class="partElements" id="part11"></div>
<div class="partElements" id="part12"></div>
<div class="partElements" id="part13"></div>
<div class="partElements" id="part14"></div>
<div class="partElements" id="part15"></div>
<div class="partElements" id="part16"></div>
<div class="partElements" id="part17"></div>
<div class="partElements" id="part18"></div>
<div class="partElements" id="part19">edit</div>
<div class="partElements" id="part20">ddelete</div>
<div class="partElements" id="part21">modify</div>
</div>