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

Javascript 如何使用jquery获取div当前文本框,javascript,jquery,html,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"> &

我有多个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>
$( "input" ).blur(function() {
            var string = $(this).val();
            $(this).closest('div').find('h3 > strong').html(string);

        });


姓名:
价值:

姓名:
价值:

姓名:
价值:

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

由于这些HTML元素是动态生成的,请使用下面的方法

   $(document).on('blur', '#attribute_name', function () {
      console.log($(this).val());  //To get the value of the textbox
      $(this).val(' ');
    });

因为这些HTML元素是动态生成的,所以使用下面的方法

   $(document).on('blur', '#attribute_name', function () {
      console.log($(this).val());  //To get the value of the textbox
      $(this).val(' ');
    });
试试这个..

 $("input[type='text']").on('blur', function () {
          alert($(this).val());  
 });
试试这个..

 $("input[type='text']").on('blur', function () {
          alert($(this).val());  
 });
这将在从输入中删除光标时追加文本。根据您的需要设计样式。至少它会让你知道该怎么做

这将在从输入中删除光标时追加文本。根据您的需要设计样式。至少它会让你知道该怎么做


终于开始工作了:)


终于开始工作了:)


感谢您的精彩回答:)但该值应显示在元素的父元素ie的上方仅在内:(在字符串中添加一些HTML。创建一个具有相对位置和背景颜色为白色的div。然后,您需要一个关闭按钮,当单击关闭按钮时,您必须删除以前创建的div。您有重复的id,这是不推荐的。修复它们并将代码发布到此处。然后,我可以根据您的需要编写一些代码。也不要这样做。)使类变得如此冗余。感谢您的精彩回答:)但此值应显示在元素的父元素上方,即..仅显示在以下位置:(在字符串中添加一些HTML。创建一个具有相对位置和背景颜色为白色的div。然后,您需要一个关闭按钮,当单击关闭按钮时,您必须删除以前创建的div。您有重复的id,这是不推荐的。修复它们并将代码发布到此处。然后,我可以根据您的需要编写一些代码。也不要这样做。)使类变得如此冗余。