[英]:button selector not working in firefox and ie
请帮助我:button选择器解除我的Spring MVC项目中所有按钮的绑定,在chrome中工作正常,但在Firefox和Internet Explorer中无法正常工作。
我的任务是从项目中的所有按钮取消绑定事件。 代码如下:
var j$ = jQuery.noConflict(); j$(document).ready(function() { jQuery(window).bind( "beforeunload", function() { return confirm("do you want to exit?" , "true"); } ); jQuery(":button").on('click', function(){ jQuery(window).unbind('beforeunload') }); jQuery('a').on('click', function(){ jQuery(window).unbind('beforeunload') }); jQuery(window).bind('keydown keyup', function(e) { if(e.which === 116) { jQuery(window).unbind('beforeunload'); } if(e.which === 82 && e.ctrlKey) { jQuery(window).unbind('beforeunload'); } }); jQuery(window).mousedown(function(e){ if( e.button == 2 ) { jQuery(window).unbind('beforeunload'); } else{ jQuery(window).bind('beforeunload'); } }); jQuery("form").submit(function(){ jQuery(window).unbind('beforeunload') }); });
现在,这在chrome中可以正常工作,但在ie和firefox中却不能。 请帮助我纠正此代码,或建议我以其他方式取消所有按钮的绑定。 提前谢谢了
嗨,我只是遇到了实际问题。 问题是由于输入元素的类型为button,这导致了问题。 如果我们将按钮的输入类型设置为“提交”,则在Firefox和其他浏览器中可以正常工作。 但是,如果按钮的输入类型设置为“ button”,则它将不起作用。 我的意思是。 请帮助我。 如何解决这个问题。 提前致谢。
哦,现在我明白你的意思了。 问题是,您已经为按钮分配了disableButton -function (在HTML内)...,然后使用Java脚本(在文档准备好之后)给THEN分配了另一个函数[ jQuery(“:button”)。on( 'click',...)... unbind() ]
问题出在调用顺序上:首先是disableButton,然后是unbind() 。 并且只有逆序才能实现所需的行为。
我的建议是要么使用Submit(就像您之前所说的,几乎没有js),要么添加j $(this).unbind(“ beforeunload”); 以disableButton() (它在firefox中也有效:-)):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<script type="text/javascript" src="demo-Dateien/jquery.js"></script>
<script type="text/javascript">
function disableButton() {
j$(this).unbind("beforeunload");
document.form.method="GET";
document.form.but.disabled = true;
document.form.submit();
}
var j$ = jQuery.noConflict();
j$(document).ready(function() {
j$(window).bind(
"beforeunload",
function() {
return confirm("do you want to exit?" , "true");
}
);
});
</script>
</head>
<body>
<form name="form" action="process.jsp" method="post">
<label>First Name</label>
<input name="fname" type="text">
<br>
<label>Last Name</label>
<input name="lname" type="text">
<br>
<input class="Button" name="but" value="Next" onclick="javascript:disableButton()" type="button">
</form>
</body>
</html>
它在Firefox中工作。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert("Hello");
});
});
</script>
</head>
<body>
<button> hello</button>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.