如何在Jquery对话框上设置内容

fis*_*h40 7 html javascript jquery

$("#note_content").dialog({
            title: "Note",
            modal: true,
            width:'auto',
            height:'auto',
            resizable:false,

            open: function(){
                var note_text = $('#note_content').attr('note_text');
     }
}
Run Code Online (Sandbox Code Playgroud)

在我的代码中我尝试将note_text设置为对话框的内容,任何想法我怎么能这样做?

cod*_*der 17

你可以试试这个:DEMO

var SplitText = "Title"
var $dialog = $('<div></div>')
    .html(SplitText )
    .dialog({
        height: 500,
        width: 600,
        title: 'Title'});

$dialog.dialog('open');

$dialog.html('Some text');
?
Run Code Online (Sandbox Code Playgroud)


Dar*_*ren 4

您的对话框中应该有一个内容占位符,例如:

<div id="noteContent" title="Basic dialog">
   <p id="contentholder"> This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

$("#note_content").dialog({
    title: "Note",
    modal: true,
    width:'auto',
    height:'auto',
    resizable:false,

    open: function(){
        var note_text = $('#note_content').attr('note_text');
       $("#contentholder").val(note_text)
    }
}
Run Code Online (Sandbox Code Playgroud)

您已将 note_text 分配给此行中的变量:

var note_text = $('#note_content').attr('note_text');
Run Code Online (Sandbox Code Playgroud)

但是,您没有将 note_text 变量分配给占位符。

  • 你的解决方案是正确的。但是 .val() 不适用于 &lt;p&gt; 标签。您需要使用 .text() 函数来覆盖内容。 (2认同)