jquery - 如何在模态对话框中设置输入值?

标签 jquery twitter-bootstrap modal-dialog jquery-events

我正在研究“添加链接”功能。为此,我使用 Modal plugin from Twitter Boostrap JS 。在主页上只有“链接”字段需要填写,当用户单击“添加链接”按钮时,会弹出一个模式,用户会看到填写 3 个字段的完整表单:链接、标题、标签。但是,我希望链接字段预先填充上一步中的值。这与您在好吃的网站上“保存链接”时发生的情况类似。

感谢 Joe 的帮助 (previous question),我可以在模式对话框中打印 linkURL,但重要的是,此 linkURL 是具有 3 个字段(链接、标题、标签)的表单的链接字段的值。知道如何做到这一点吗?

<html>
<head>
  <title>Example</title>
  <script src="scripts/jquery.min.js"></script>
  <script src="scripts/bootstrap-modal.js"></script>
  <link rel="stylesheet" href="scripts/bootstrap.min.css">
  <link rel="stylesheet" href="main.css" />

  <script type="text/javascript">
            $(document).ready(function()
            {
                $('#modal-from-dom').bind('show',function()
                {
                    $(".modal-body").html($("#linkURL").val());
                });
            });
    </script>
</head>
<body>
  <!-- The Modal Dialog  -->
          <div id="modal-from-dom" class="modal hide fade">
            <div class="modal-header">
                <a href="#" class="close">&times;</a>
                <h3>Add Link</h3>
            </div>
            <div class="modal-body">
            <!--
            <form id='post-on-wall' method='POST' action='savePost.php' enctype='multipart/form-data'>"
        <input type='text' class='label-inline' name='linkURL' id='wall-post' value=linkURL>
            </form>
            -->
            </div>
            <div class="modal-footer">
                <a href="#" class="btn primary">Add Link</a>
            </div>
        </div>
  <div class="container">
    <div class="wall-post">
        <textarea class='label-inline' name='linkURL' id='linkURL'></textarea>
        <button data-controls-modal="modal-from-dom" data-backdrop="true" data-keyboard="true" class="btn">Add Link</button>
    </div>
  </div>

</body>

最佳答案

      $('#modal-from-dom').bind('show',function()
            {
                $(".modal-body #wall-post").val($("#linkURL").val());
            });

还是我错过了什么? :)

关于jquery - 如何在模态对话框中设置输入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7845866/

相关文章:

wpf - 使用 MVVM 显示新窗口并获取更新数据

jquery - CSS,选择所有一级元素

jquery - 将事件跟踪代码从 Jquery 转换为 Mootools

jquery - 在 Bootstrap 中创建侧边菜单?

html - 为什么我的最小宽度和最大宽度不适用?

c++ - 按下回车按钮时如何使用 C++ Win32 API 调用按钮?

html - 如何在不关闭 html/css 模式的情况下更改图像

jquery - 幻灯片后,保持位置

jquery - 如何使用 jquery 设置选择下拉列表的 'selected option'

javascript - Bootstrap 中嵌套选项卡的 prev next 函数