10 回答
TA贡献5条经验 获得超4个赞
<script type="text/javascript">
$(function(){
$("#userInput").keyup(function(){
$("#userInputResult").html($(this).val());
});
$("#userInput").keydown(function(){
$("#userInputResult").html($(this).val());
});
});
</script>
<input type="text" id="userInput" />
<span id="userInputResult"></span>
这样做!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 或者用AngularJS的双向数据绑定
TA贡献96条经验 获得超43个赞
使用input事件和propertychange事件(IE专属),你去百度下就知道了
或者使用keydown事件,或者keyup事件
另外,使用change事件应该是不行的,会有缺陷
TA贡献885条经验 获得超1144个赞
用JQuery,如有以下HTML代码:
<input type="text" id="userInput" /> <span id="userInputResult"></span>
比如我要实现用户在#userInput文本框中输入时,在#userInputResult中实时显示,可以这么写:
$("#userInput").change(function(){
$("#userInputResult").html($(this).val());
});是不是很简单呢?
TA贡献280条经验 获得超233个赞
TA贡献16条经验 获得超0个赞
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
function getValue(){
//获取id为nameId的节点
var inputEle = document.getElementById("nameId");
var targetEle =document.getElementById("target");
//获取value
var a = inputEle.value;
targetEle.innerHTML=a;
}
</script>
</head>
<body>
<input onkeydown="getValue();" type="text" name="name" id="nameId"/><!--绑定失去焦点的方法-->
<p id="target"></p>
</body>
</html>写的不太好,总是少一个字符,要是用ajax可能会容易一些
添加回答
举报
