js同时触发了change和click两个事件,怎么执行一个之后就退出 那不绑定click就可以了啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 change事件不是因为点击按钮才触发的啊,应该是onblur时,就会触发change事件,就是当你的input框失去焦点时,就会触发这个change事件。按你说的意思,我觉得change事件是不需要的,可以把change事件的处理逻辑,放到click事件内处理的啊。 change事件需要对文本框的输入进行校验,确认按钮的click事件需要对所有的输入进行校验,不能放在一起。 <!doctype html><html lang="zh-cn"><head> <meta charset="utf-8"> <style>*{margin:0;padding:0;}div{padding:20px;}a{padding:10px;}</style> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script></head><body> <script> $(function(){ var $b1 = $("#b1"); $b1.on("click",function(){ alert("检测中...") }); $("#t1").on({ change:function(){ $b1.off("click","**"); alert("change!") $b1.on("click"); } }) }) </script> <div id="wrapper"> <header id="header"></header> <div> <input type="text" id="t1" placeHolder="hello,world!" /> <input type="button" id="b1" value="检测" /> </div> </div></body></html> <!doctype html><html lang="zh-cn"><head> <meta charset="utf-8"> <style>*{margin:0;padding:0;}div{padding:20px;}a{padding:10px;}</style> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script></head><body> <script> $(function(){ var $b1 = $("#b1"); var $t1 = $("#t1"); var handleClick = function(e){ console.log("检测中...") } $b1.on("click",handleClick); $t1.on({ change:function(){ $b1.off("click",handleClick); console.log("change!"); setTimeout(function(){ $b1.on("click",handleClick); },100); } }) }) </script> <div id="wrapper"> <header id="header"></header> <div> <input type="text" id="t1" placeHolder="hello,world!" /> <input type="button" id="b1" value="检测" /> </div> </div></body></html> 假设文本框是textInput, 按钮是enterButton:textInput.addEventListener('change', onTextChange, false);enterButton.addEventListener('click', onButtonCLick, false);var _valid = true; //当前文本是否校验通过function onTextChange(){ if(校验条件){ _valid = true; }else{ _valid = false; }}function onButtonClick(){ if(_valid ===true){ //如果文本校验通过 }else{ //否则 }}change事件会在文本的编辑过程中不断被触发, 而click事件只会在点击时触发一次. 那你把按钮的click事件去掉不就行了~~~我擦~ 求大神 Swordweb组件 Tab页的关闭效果 求下拉导航效果 关于收缩展开菜单的JS问题,请进! 怎样获取上上个页面的地址? javascript变量的问题 简单问题 当鼠标在一个链接上时,怎样同时放大对应的图像? 改变图像的问题。 请教:表单中有4列多行checkbox.我想实现在提交时每列checkbox中至少有一个checkbox被选中。 如何控制DIV滚动条的位置? 关于给src赋值时造成的浏览器死掉的问题 easyui 的formatter函数如何处理html的代码
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<style>*{margin:0;padding:0;}div{padding:20px;}a{padding:10px;}</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body>
<script>
$(function(){
var $b1 = $("#b1");
$b1.on("click",function(){
alert("检测中...")
});
$("#t1").on({
change:function(){
$b1.off("click","**");
alert("change!")
$b1.on("click");
}
})
})
</script>
<div id="wrapper">
<header id="header"></header>
<div>
<input type="text" id="t1" placeHolder="hello,world!" />
<input type="button" id="b1" value="检测" />
</div>
</div>
</body>
</html>
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<style>*{margin:0;padding:0;}div{padding:20px;}a{padding:10px;}</style>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
</head>
<body>
<script>
$(function(){
var $b1 = $("#b1");
var $t1 = $("#t1");
var handleClick = function(e){
console.log("检测中...")
}
$b1.on("click",handleClick);
$t1.on({
change:function(){
$b1.off("click",handleClick);
console.log("change!");
setTimeout(function(){
$b1.on("click",handleClick);
},100);
}
})
})
</script>
<div id="wrapper">
<header id="header"></header>
<div>
<input type="text" id="t1" placeHolder="hello,world!" />
<input type="button" id="b1" value="检测" />
</div>
</div>
</body>
</html>
if(校验条件){
_valid = true;
}else{
_valid = false;
}
}function onButtonClick(){
if(_valid ===true){
//如果文本校验通过
}else{
//否则
}
}change事件会在文本的编辑过程中不断被触发, 而click事件只会在点击时触发一次.