这是一个简单的代码,它接受输入并将其打印在同一页面上。但当我点击按钮时它不起作用。请帮忙解决这个问题。
<html>
<head>
<script>
function changeHTML() {
$("#withjQuery").html($("#theInput").val());
}
</script>
<body>
<input type='text' id='theInput' value='Write here' />
<input type='button' onClick='changeHTML();' value='See what you wrote with jQuery.html'/>
<div id="withjQuery"></div>
</body>
</head>
最佳答案
您的页面中没有包含 jQuery 库
添加
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
例如
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
function changeHTML() {
$("#withjQuery").html($("#theInput").val());
}
</script>
</head>
<body>
<input type='text' id='theInput' value='Write here' />
<input type='button' onClick='changeHTML();' value='See what you wrote with jQuery.html'/>
<div id="withjQuery"></div>
</body>
</html>
演示:Fiddle
关于javascript - 简单的 jquery 无法打印输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18168855/