javascript - 如何使用jquery获取div当前文本框

标签 javascript jquery html

我有多个带有文本框的 div,想要获取每个 div 输入框的值并将其显示到那个 div 本身

HTML :

 <div id="product_data" class="ui-sortable">
  <div class="clonedInput" id="add_attribute" style="display: block;">
    <div id="add_attributes">
      <div id="accordion1">
        <h3>
          <input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
          <strong class="attribute_name"></strong> </h3>
          <table cellspacing="0" cellpadding="0" id="attribute_data" class="">
          <tbody>
            <tr>
              <td class="attribute_name"><label>Name:</label>
                <input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
              </td>
              <td rowspan="3"><label>Value(s):</label>
                <textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
  <div class="clonedInput" id="add_attribute_2" style="display: block;">
    <div id="add_attributes" class="woocommerce_attribute wc-metabox ">
      <div id="accordion1">
        <h3>
          <input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
          <strong class="attribute_name"></strong> </h3>
          <table cellspacing="0" cellpadding="0" id="attribute_data" class="">
          <tbody>
            <tr>
              <td class="attribute_name"><label>Name:</label>
                <input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
              </td>
              <td rowspan="3"><label>Value(s):</label>
                <textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
  <div class="clonedInput" id="add_attribute_3" style="display: block;">
    <div id="add_attributes" class="woocommerce_attribute wc-metabox ">
      <div id="accordion1">
        <h3>
          <input type="button" value="Remove" class="btnDel remove_row button" name="btnDelete1">
          <strong class="attribute_name"></strong> </h3>
          <table cellspacing="0" cellpadding="0" id="attribute_data" class="">
          <tbody>
            <tr>
              <td class="attribute_name"><label>Name:</label>
                <input type="text" id="attribute_name" class="attribute_name" name="attribute_names[]">
              </td>
              <td rowspan="3"><label>Value(s):</label>
                <textarea name="attribute_values[]" cols="5" rows="5" placeholder="Enter some text, or some attributes"></textarea>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

我正在尝试获取输入字段值“id = attribute_name”并将该值显示到模糊函数的“”中,这是动态文本框

最佳答案

$( "input" ).blur(function() {
   var string = $(this).val();
   $(this).parent().append(string);
});

这将在从输入中移除光标时追加文本。根据您的要求设置样式。至少它应该让您知道该怎么做。

http://jsfiddle.net/L4UQJ/

关于javascript - 如何使用jquery获取div当前文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20062991/

相关文章:

javascript - MongoDB mapReduce 多键值计数问题

javascript - 使用 Javascript 将动画 GIF 分享到 Facebook

javascript - 在 AngularJs 中查找元素并更改其内容

javascript - 使用 Javascript/CSS 的内容幻灯片

javascript - 在我使用 javascript + 假超链接隐藏当前内容并显示新内容的页面上启用 "Back"

html - 我试图在图像中间对齐文本。我不确定我在这里做错了什么

javascript - 动态D3力图

javascript - 什么时候需要转义正则表达式字符集中的字符([] 内)?

jquery - 如何使用 jquery 将输入值从一个输入传输到另一个输入

jquery - Animate.css 网站颜色渐变动画