脚本不工作onclick

时间:2014-03-20 09:35:13

标签: html jscript

我找到了一个对话框脚本http://jsfiddle.net/taditdash/vvjj8/,我想与button onclick一起使用。但它不起作用。 任何帮助?

我的修改

<input type="button" id="btnOpenDialog" value="Open Confirm Dialog"    onclick="fnOpenNormalDialog()"/>
<div id="dialog-confirm"></div>

function fnOpenNormalDialog() {
    $("#dialog-confirm").html("Confirm Dialog Box");

    // Define the Dialog and its properties.
    $("#dialog-confirm").dialog({
        resizable: false,
        modal: true,
        title: "Modal",
        height: 250,
        width: 400,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                callback(true);
            },
                "No": function () {
                $(this).dialog('close');
                callback(false);
            }
        }
    });
}

function callback(value) {
    if (value) {
        alert("Confirmed");
    } else {
        alert("Rejected");
    }
}

2 个答案:

答案 0 :(得分:1)

只需将标记中的javascript函数包含在HTML块中,如下所示:

<input type="button" id="btnOpenDialog" value="Open Confirm Dialog"    onclick="fnOpenNormalDialog()"/>
<div id="dialog-confirm"></div>
<script>
    function fnOpenNormalDialog() {
    $("#dialog-confirm").html("Confirm Dialog Box");
    // Define the Dialog and its properties.
    $("#dialog-confirm").dialog({
        resizable: false,
        modal: true,
        title: "Modal",
        height: 250,
        width: 400,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                callback(true);
            },
                "No": function () {
                $(this).dialog('close');
                callback(false);
            }
        }
    });
}
function callback(value) {
    if (value) {
        alert("Confirmed");
    } else {
        alert("Rejected");
    }
}
</script>

演示: http://jsfiddle.net/vvjj8/106/

答案 1 :(得分:0)

使用它:

<button value="click me" onclick="fnOpenNormalDialog()">

您需要添加函数调用的括号才能成功。