简体   繁体   English

如何使用 jquery 设置文本框数组元素的值?

[英]How do I set the value of a textbox array element using jquery?

how can i set a value to a textbox array element using jquery.如何使用 jquery 为文本框数组元素设置值。 i have an array of select and corrosponding textbox(array).我有一个 select 数组和对应的文本框(数组)。 when i select a diff value from the dropdown, it shud automatically populate the textbox corrosponding to it.当我 select 下拉列表中的差异值时,它会自动填充与其对应的文本框。 also remember this select and textbox are created dynamically.还记得这个 select 和文本框是动态创建的。

thanks in advance提前致谢

Just do something like this:只需执行以下操作:

var $text = $('#textbox'), $select = $('#selectMenu').change(function(){
  $text.val($select.val())
})
$('#myTextBox').val($('#mySelectBox').val());

You can add onChange to the select box to call the js function to do the above.可以在 select 框中添加 onChange 调用 js function 来做上面的事情。

You should try something like:您应该尝试以下方法:

$(function () {   
    function changed(select) {
         var newVal = select.value;
         ${"#yourTextBoxID"}.val(newVal);
     }
});

... and on your select ...在您的 select 上

onchange="changed(this)" onchange="改变(这个)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM