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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10362295/
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-08-24 01:02:37  来源:igfitidea点击:

how to set content on Jquery dialog

javascriptjqueryhtml

提问by fish40

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

            open: function(){
                var note_text = $('#note_content').attr('note_text');
     }
}

In my code I am trying set note_text as content of dialog, any idea how could I do this?

在我的代码中,我尝试将 note_text 设置为对话框的内容,知道我该怎么做吗?

采纳答案by Darren

You should have a content place holder inside your dialog, for example:

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

<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)
    }
}

You had your note_text assigned to a variable in this line:

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

var note_text = $('#note_content').attr('note_text');

However, you didn't assign the note_text variable to the placeholder.

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

回答by coder

You can try this: DEMO

你可以试试这个:DEMO

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

$dialog.dialog('open');

$dialog.html('Some text');
?

?

?

?

?