javascript 如何获取模态框 jquery UI 的输入值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15473050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 00:54:37  来源:igfitidea点击:

How to get input value to modal box jquery UI

javascriptjquery

提问by Emanuel

<div id="befor-box">
   <form id="newsletter-form" name="newsletter-form" action="/sub/" method="post">{% csrf_token %}
      <input name="email" type="text" value="Enter your Email here" class="text"/> 
      <input class="submit" onclick="showDialog();" value="Subscribe!" />
   </form>
</div>

How to get EMAIL value from:

如何从以下位置获取 EMAIL 值:

<input name="email" type="text" value="Enter your Email here" class="text"/>

<input name="email" type="text" value="Enter your Email here" class="text"/>

to:

到:

<input name="email" type="text" value="" class="text"/>

<input name="email" type="text" value="" class="text"/>

from here:

从这里:

<div id="dialog-modal" style="display:none;">
   <form name="newsletter-form" action="/sub/" method="post">
      <input name="email" type="text" value="" class="text"/>
      <input name="fname" type="text" value="First name" class="text"/>
      <input name="lname" type="text" value="Last name" class="text"/>
      <input type="submit" class="submit" value="Subscribe!" />
   </form>
</div>
<script type="text/javascript">
   function showDialog()
   {
   $( "#dialog-modal" ).dialog({


   });
   }
</script>

采纳答案by bipen

use open event of dialog which is called whn dialog opens... so replace the value there..

使用对话框的打开事件,它被称为对话框打开时...所以替换那里的值..

$( "#dialog-modal" ).dialog({
 open: function( event, ui ) {
     var boxInput=$("#befor-box").find('input[name="email"]').val(); //get the value..
     $("#dialog-modal").find('input[name="email"]').val(boxInput); //set the valu

 }
});

回答by Wiseman

Emanuel, start by reading some useful info:

伊曼纽尔,首先阅读一些有用的信息:

http://www.w3schools.com/jquery/jquery_selectors.asp"The #id Selector" chapter especially.

http://www.w3schools.com/jquery/jquery_selectors.asp尤其是“#id 选择器”一章。

After that, you can add 'id' attributes to your DOM structure and retrieve input value as simple as

之后,您可以将 'id' 属性添加到您的 DOM 结构中,并像检索输入值一样简单

$('#my-input-id').val()

回答by Iker Vázquez

Add an id on both inputs:

在两个输入上添加一个 id:

<input name="email" type="text" value="Enter your Email here" class="text" id="email_orig"/>

<input name="email" type="text" value="" class="text" id="email_dst"/>

Then override the open event:

然后覆盖 open 事件:

    function showDialog()
    {
    $( "#dialog-modal" ).dialog({
         open: function(){
         $("#email_dst").val($("#email_orig").val())
    }
    });

回答by Faridul Khan

You can use:

您可以使用:

$("input[name=email]");

For Bootstrap Modal:

对于 Bootstrap 模态:

$('.modal-body input[name=email]').val(email);