JS 实时监听input的value值改变 解决方案

该方案在 FoxFire、Chrome、360急速、Microsoft Edge、IE11下测试均可以正常显示。
html页面代码:
 
  
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试页面</title>
<link type="text/css" rel="stylesheet" href="../css/myhtml5.css"/>
</head>
<body>
<div><h1>测试输入框事件监听</h1></div>
<div>
<table>
<tr><th><span>点击输入框,输入字符:</span></th></tr>
<tr><td><input id="input_text" type="text" placeholder="点击输入" value=""/></td></tr>
<tr><td><input id="input_button" type="button" value="点击结束" name="完成"/></td></tr>
</table>
</div>
<script src="../scripts/jq.js"></script>
<script src="../scripts/myhtml5.js"></script>
</body>

js代码:
 
  
$(document).ready(function () {

$("#input_text").bind("input propertychange",function () {
$("#input_button").val("已经输入了"+$("#input_text").val().length+"个字。。。");
});

$("#input_button").click(function () {
alert($("#input_text").val()+"\n"+$(this).val());
});
});

猜你喜欢

转载自blog.csdn.net/qq_20112609/article/details/65440593