更新按钮上的输入值单击Jquery [英] Updating the input value on button click Jquery

查看:85
本文介绍了更新按钮上的输入值单击Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于下面的代码,单击该按钮时,应该更新文本名称。即heally,hellosally,supsally,
但相反,当前是热门的,听觉上,suptomally。
我想知道是否有任何方法更新名称,同时保持文字hi,hellop和sup。
非常感谢

For The code below, when the button is clicked, it's supposed to update the name of the text. ie hisally, hellosally, supsally, but instead the current is hitomsally, hellotomsally, suptomsally. i m wondering is there any way to update the name while keeping the text hellop and sup. Many thanks

$(".ok").on('click', function() {
  var set = $(this).closest('tr').find('.done').val();
  if (set) {
    $(this).closest('tr').find('.text').each(function() {
      $(this).val($(this).attr("data-value") + set);
    })
  }
});

<table>
  <tr>

    <td>
     <input type="button" value="ok" class="ok"></td>
    <td>done<input type="text" value="sally" class="done" \> </td>
    <td>text1<textarea class="text" data-value="hitom">hitom</textarea> </td>
    <td>text2<textarea class="text" data-value="hellotom">hellotom</textarea> </td>
    <td>text3<textarea class="text" data-value="suptom">suptom</textarea> </td>

  </tr>
</table>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>

推荐答案

您需要将数据值更改为您希望在<$ c中添加的值$ c> textarea

you need to change your data-value to only the values that you want to prepend in textarea

$(".ok").on('click', function() {
  var set = $(this).closest('tr').find('.done').val();
  if (set) {
    $(this).closest('tr').find('.text').each(function() {
      $(this).val($(this).attr("data-value") + set);
    })
  }
});

<table>
  <tr>

    <td>
     <input type="button" value="ok" class="ok"></td>
    <td>done<input type="text" value="sally" class="done" \> </td>
    <td>text1<textarea class="text" data-value="hi">hitom</textarea> </td>
    <td>text2<textarea class="text" data-value="hello">hellotom</textarea> </td>
    <td>text3<textarea class="text" data-value="sup">suptom</textarea> </td>

  </tr>
</table>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>

这篇关于更新按钮上的输入值单击Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆