从表内的输入框获取输入
<!DOCTYPE html>
<html>
<head>
<style>
p { color:blue; margin:8px; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
//region 1
<!--<input type="text" class="plo" value="some text"/>
<input type="text" class="plo" value="some text"/>
<input type="text" value="some text"/>-->
//region 2
<!-- <table>
<tr><td><input type="text" class="plo" value="some text"/></td></tr>
<tr><td><input type="text" class="plo" value="some text"/></td></tr>
<tr><td><input type="text" value="some text"/></td></tr>
</table>
-->
<p></p>
<script>
/*$(".plo").keyup(function () {
var value = $(this).val();
$("p").text(value);
}).keyup();*/
/*$(".plo").keyup(function () {
var value = $(this).val();
$("p").text(value);
}).keyup();*/
$(".plo:last").keyup(function () {
var value = $(this).val();
$("p").text(value);
}).keyup();
</script>
</body>
</html>
在此代码中,选择了中间的输入框,每当用户在其中输入任何内容时,它都会在下一行中再次显示。问题是如果使用区域 1,它可以正常工作,但是如果使用区域 2,即它放置在表中,则它不能正常工作。我有一个 10x10 的表格,我需要处理每个单元格的输入。请帮忙
<!DOCTYPE html>
<html>
<head>
<style>
p { color:blue; margin:8px; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
//region 1
<!--<input type="text" class="plo" value="some text"/>
<input type="text" class="plo" value="some text"/>
<input type="text" value="some text"/>-->
//region 2
<!-- <table>
<tr><td><input type="text" class="plo" value="some text"/></td></tr>
<tr><td><input type="text" class="plo" value="some text"/></td></tr>
<tr><td><input type="text" value="some text"/></td></tr>
</table>
-->
<p></p>
<script>
/*$(".plo").keyup(function () {
var value = $(this).val();
$("p").text(value);
}).keyup();*/
/*$(".plo").keyup(function () {
var value = $(this).val();
$("p").text(value);
}).keyup();*/
$(".plo:last").keyup(function () {
var value = $(this).val();
$("p").text(value);
}).keyup();
</script>
</body>
</html>
In this code, the middle input box is chosen and whenever a user enters anything in it, it is displayed again in the next line. The problem is if region 1 is used, it works fine but if region 2 is used, i.e. its placed in a table, then it doesn't. I have a 10x10 table and I need to process the inputs from each of the cells. Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道为什么要注释掉 HTML 源代码和 JavaScript,但是在取消注释 HTML 并将代码更改为在
$(document).ready()
中运行(并删除冗余调用),注释掉的 JavaScript 就达到了预期的效果。Not sure why you're commenting out both your HTML source and your JavaScript, but after uncommenting your HTML, and changing your code to run in
$(document).ready()
(and removing a redundant call), your commented-out JavaScript has the desired effect.