繁体   English   中英

按下Enter键时,如何查找在模态输入中键入的值以及如何更改另一个输入的值

[英]How to find the value that is typed in the modal input and change the value of another input when enter key is pressed

我需要获取我在模态输入字段中键入的值,当我按Enter键时,模态将关闭,并且我键入的输入值将显示在模态外部的另一个输入字段中。

  $('#myModal2').on('keydown', function(e) { if (e.which == 13) { e.preventDefault(); var value = $(this).find('td:eq(myInput2)').text(); document.getElementById("my_member").value = value; $("[data-dismiss=modal]").trigger( { type: "click" }); } }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!-- modal button --> <button type="button" class="btn btn-outline-secondary" style="background- color:#e6e6e6; " data-toggle="modal" data-target="#myModal2" id="btnproduct2" name="btnproduct2">...</button> <!-- input field inside modal --> <div class="modal fade" id="myModal2" role="dialog"> <input type="text" class="form-control" placeholder="ID..." id="myInput2" autocomplete="off" /> </div> <!-- input field outside modal --> <input type="text" class="form-control" name="my_member" style="width:75%;" id="my_member" value="" autocomplete="off"> 

更好地处理提交按钮上的单击事件。 然后在Enter Pressing上触发Button Click Event。

在点击和输入时触发事件

关于在模式关闭后更改文本值。 您应该使用jquery方法而不是javascript。

jQuery更改输入文本值

下次,在询问之前尝试更多。 干杯。

PS:如果将jQuery添加到页面,请使用jQuery方法而不是JavaScript。

暂无
暂无

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

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