0

基于此链接:如何构建一个 jQuery 对话框以确认(是/否)可以在应用程序的任何位置工作?
我有以下代码,使用 IE 8

HTML

<ol>
    <li>
        <span class="title">Item 1</span>
        <span class="test">test dialog</span>
    </li>
</ol>

Javascript

function MergeRenameDialog(button1, button2) {
    var btns = {};
    btns[button1] = function() {
        alert($('#mergedPreDefinedNewFilterName').val())
        $(this).dialog("close");
    };
    btns[button2] = function() {
        // Do nothing
        $(this).dialog("close");
    };
    $("<div id='MergeRenameDiv' style='text-align:left'><label>Keyin your New Filter Name.</label><br><br><input id='mergedPreDefinedNewFilterName' /></div>").dialog({
        autoOpen: true,
        width: 450,
        height: 200,
        modal: true,
        resizable: false,
        position: 'center',
        title: 'xxx',
        modal: true,
        buttons: btns
    });
}
$('.test').click(function() {
    MergeRenameDialog('Check Value ', 'Close ');
})

在页面加载:
1.点击测试对话框,在输入字段中键入一个值,然后点击检查值按钮,它会给你当前输入字段的值,然后对话框将关闭
2.再次点击测试对话框,在输入一个值输入字段并单击检查值按钮,它将为您提供以前的输入字段值,然后对话框将关闭

JsFiddle在这里

问:如何在对话框中获取最新的字段值?

谢谢

4

1 回答 1

0

您可以尝试像这样打开对话框

<ol>
<li>
    <span class="title">Item 1</span>
    <span class="test">test dialog</span>
</li>
</ol>
<div id='dialogshow'></div>

function MergeRenameDialog(button1, button2) {
document.getElementById('dialogshow').innerHTML = "<div id='MergeRenameDiv' style='text-align:left'><label>Keyin your New Filter Name.</label><br><br><input id='mergedPreDefinedNewFilterName' /></div>";
$( "#dialogshow" ).dialog({
    width: 450,
    height: 300,
    modal: true,
    resizable:false,
    title: 'xxx',
    buttons: {
        Checkvalue: function()
        {
            alert($('#mergedPreDefinedNewFilterName').val());
                            $( this ).dialog( "close" );
        },
        Close: function() {
            $( this ).dialog( "close" );
        }
    }
});

}

$('.test').click(function() {
MergeRenameDialog('Check Value ', 'Close ');
})​;

检查这个小提琴

于 2012-11-29T04:07:58.960 回答