简体   繁体   English

如何从具有动态 ID 的动态文本框获取值

[英]How to get value from dynamic textbox with dynamic id

So i have a text box with id :所以我有一个带有 id 的文本框:

 <input type="text" name="jview_no[]" id="view'+$sr +'" value="1">

where :在哪里 :

$sr = ($(".my_tr_class").length + 1);

i wanted to put the value of that view+$sr to another textbox, so this is how i do it so far :我想把那个 view+$sr 的值放到另一个文本框,所以到目前为止我是这样做的:

<input type="text" name="amount[]" value="'+ $("#view"+$sr).val() + '" > 

but the result is undefined.但结果是不确定的。

the thing is, i don't really know how to do it the right way, would you guys please help me ?问题是,我真的不知道如何以正确的方式做到这一点,你们能帮我吗?

thanks in advance提前致谢

I don't understand what you exactly want to achieve.我不明白你到底想达到什么目的。 If you have only two inputs you can use example below (this is only for your example), but if you have more inputs and you need to match these inputs together, you have read about this in javascript.如果你只有两个输入你可以用下面的例子(这仅仅是你的例子),但如果你有更多的投入,你需要这些输入搭配在一起,您已经阅读关于this在JavaScript。

 $(document).on('keyup','input[name="jticket_no[]"]', function(){ $(this).parent().next().children()[0].value = $(this).val() })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table style="width: 100%" class="table"> <thead><tr><th>No.</th> <th>Views +5</th> <th>Payment</th> </tr> </thead> <tbody id="table-details"><tr id="row1" class="jdr1"> <td><span class="btn btn-sm btn-default">1</span><input type="hidden" value="6437" name="count[]"></td> <td><input type="text" required="" class="form-control input-sm" placeholder="Views" name="jticket_no[]"></td> <td><input type="text" required="" data-parsley-type="digits" class="form-control input-sm" placeholder="Payment" name="jamount[]"></td> </tr> <tr id="row1" class="jdr1"> <td><span class="btn btn-sm btn-default">2</span><input type="hidden" value="6437" name="count[]"></td> <td><input type="text" required="" class="form-control input-sm" placeholder="Views" name="jticket_no[]"></td> <td><input type="text" required="" data-parsley-type="digits" class="form-control input-sm" placeholder="Payment" name="jamount[]"></td> </tr> </tbody> </table>

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

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