我有一些代码,我循环遍历页面上的所有选择框,并将.hover
事件绑定到它们,以便在它们的宽度上做一些麻烦mouse on/off
.
这发生在页面准备就绪并且工作得很好.
我遇到的问题是,我在初始循环后通过Ajax或DOM添加的任何选择框都不会受到事件限制.
我找到了这个插件(jQuery Live Query Plugin),但在我用插件添加另外5k到我的页面之前,我想知道是否有人知道这样做的方法,无论是直接使用jQuery还是通过其他选项.
<a href="https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h" id="leave">click here to leave the page</a>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Changes made may not be saved.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$("#leave").click(function() {
$(window).bind('beforeunload', function() {
return 'Changes you made may not be Saved';
});
});
Run Code Online (Sandbox Code Playgroud)
我正在处理html中的表单提交。请看下面的代码
<form id="form1">
<button id="btn1" onclick="clicked();">Submit</button>
</form>
<script>
$("#btn1").click(function (event) {
alert("event triggered");
if(some_condition == true){
// stop firing onclick method but it always submits the form
event.stopImmediatePropogation(); // not working
event.preventDefault(); // not working
event.stopPropogation(); // not working it's for bubbled events
}
});
function clicked(){ alert("clicked me"); }
</script>
Run Code Online (Sandbox Code Playgroud)
我想停止clicked()
触发附加到内联onclick
属性的函数。我想运行我的jquery click函数,如果出现问题,我不想触发onclick,但它总是运行clicked()函数。谁能帮我。任何帮助是极大的赞赏。