您的位置:首页 > 产品设计 > UI/UE

js动态改变value 不触发onchange事件解决办法

2017-02-07 21:57 585 查看

js动态改变input的value 不触发onchange事件解决办法

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<input type="text" id="two" /><br/>
<select id="three" >
<option>河北</option>
<option>西藏</option>
<option>新疆</option>
</select>
</body>
</html>
<script type="text/javascript">
var two =  document.getElementById("two");
var three =  document.getElementById("three");
function init(){
if("\v"=="v"){//IE浏览器
two.onpropertychange=changeValue;
}else{ // 其他浏览器
two.addEventListener("input",changeValue(),false);
}
}
three.onchange=function (){
two.value=three.value;
init();
}
function changeValue(){
alert(two.value);
}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息