如何通过javascript将值传递给文本框

时间:2013-05-16 19:52:15

标签: javascript jquery

我使用bootstrap框架调用模式对话框 - 我试图从mysql表中传递一个唯一值,具体取决于所单击的行。

我的代码工作到了将值传递给对话框的程度,但我不能让它显示在文本框中。 h3现在将它显示在标题中。

这是工作代码的链接。 http://jsfiddle.net/ZEpLV/14/

以下是我的代码:

<div id="com" class="modal hide fade in" style="display: none; ">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
            <h4>Server ID:<h3>PLace for your id</h3>

    <div class="modal-body">
        <h4>Text in a modal</h4>
        <input value="" type="text" name="id" Value="">
        <p>You can add some text here.</p>              
    </div>

    <div class="modal-footer">
        <a href="#" class="btn btn-success">Call to action</a>
        <a href="#" class="btn" data-dismiss="modal">Close</a>
    </div>
    <script>

    $(".modal-toggler").click(function(){
    var _id = $(this).attr("id");
    $("#com h3").text(_id);
    $("#com").show();
    return false;
});
</script>

2 个答案:

答案 0 :(得分:3)

对于输入,您需要使用.val()代替.text()

$("#com input").val(_id);

答案 1 :(得分:1)

为文字提供ID并使用文本字段ID和.val()

$("#text").val(_id);

http://jsfiddle.net/chauhangs/ZEpLV/15/

 $(".modal-toggler").click(function(){
   var _id = $(this).attr("id");
   $("#com h3").text(_id);
   $("#text").val(_id);
   $("#com").show();
   return false;
});
相关问题