从表内的输入框获取输入

发布于 2025-01-02 19:42:21 字数 1347 浏览 4 评论 0原文

<!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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2025-01-09 19:42:22

不知道为什么要注释掉 HTML 源代码和 JavaScript,但是在取消注释 HTML 并将代码更改为在 $(document).ready() 中运行(并删除冗余调用),注释掉的 JavaScript 就达到了预期的效果。

$(document).ready(function () {
    $(".plo").keyup(function() {
        var value = $(this).val();
        $("p").text(value);
    });
});

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.

$(document).ready(function () {
    $(".plo").keyup(function() {
        var value = $(this).val();
        $("p").text(value);
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文