javascript ok取消弹出按钮

时间:2011-02-24 02:23:43

标签: javascript

我尝试了很多东西,但仍然可以从表单中访问.js文件:拜托,有人能告诉我它是如何完成的吗?

这就是我想说的:

 <script type="text/javascript">
    if (confirm("Press 'OK' to leave, or 'Cancel' if you want to stay: "))
    {         
       window.location="http://google.com";
    }
    else
    {         
      <a href="javascript:history.go(-1)">Go back</a> 
    }
  </script>

这就是我试图打电话的方式:

<input type="BUTTON" value="Back to Main Page" onclick= ??? >

谢谢。

4 个答案:

答案 0 :(得分:3)

var answer = confirm ("Press Ok to leave. Cancel to stay.")
   if (answer)
window.location="http://google.com"
   else
window.location="http://www.mysite.com/"

答案 1 :(得分:0)

您正在JavaScript代码中添加HTML代码。你需要将它们分开。类似的东西:

document.write('<a href="javascript:history.go(-1)">Go back</a>');

会做到这一点。

答案 2 :(得分:0)

您需要将代码设置为javascript function,就像这样

function sayHello()
{
  alert('hello');
}

按钮html:

<input type="BUTTON" value="Back to Main Page" onclick="javascript: sayHello();" >

答案 3 :(得分:-2)

//  start active and inactive confirm message box
    var Regionid = '@Model.RegionID';
    if (Regionid != 0) {
        $(function () {
            $('#inactive').change(function () {
                $("#ConformationDlg").html('@Constants.ChangeStatus');
                $("#ConformationDlg").dialog({
                    title: "",
                    buttons: [
                       {
                           text: "Yes",
                           click: function () {
                               $("#ConformationDlg").dialog("close");
                           }
                       },
                    {
                        text: "No",
                        click: function () {
                            $('#active').prop("checked", true);
                            $("#ConformationDlg").dialog("close");
                        }
                    }
                    ]
                });
            });
        })
    }
    //  End active and inactive confirm message box
$(function () {
    $("#btnSubmit").click(function () {

        var form = $("#frm");
        var Regionid = $("#hdnRegionID").val();
        if (form.valid()) {
            if (Regionid == 0) {

                $("#ConformationDlg").html('@Constants.AddFormSubmit');
                $("#ConformationDlg").dialog({
                    title: "",
                    buttons: [
                       {
                           text: "Yes",
                           click: function () {
                               window.location.href = "../RegionFoodTypes/RegionFoodTypes";
                               $("#ConformationDlg").dialog("close");
                           }
                       },
                    {
                        text: "No",
                        click: function () {
                            $("#ConformationDlg").dialog("close");
                        }
                    }
                    ]
                });
            }
            else {

                $("#ConformationDlg").html('@Constants.EditFormSubmit');
                $("#ConformationDlg").dialog({
                    title: "",
                    buttons: [
                       {
                           text: "Yes",
                           click: function () {
                               window.location.href = "../RegionFoodTypes/RegionFoodTypes";
                               $("#ConformationDlg").dialog("close");
                           }
                       },
                    {
                        text: "No",
                        click: function () {
                            $("#ConformationDlg").dialog("close");
                        }
                    }
                    ]
                });

            }
        }
    })

})
function resetFields(form) {
    $("#ConformationDlg").html('@Constants.CancelForm');
    $("#ConformationDlg").dialog({
        title: "",
        buttons: [
           {
               text: "Yes",
               click: function () {
                   window.location.href = "../RegionFoodTypes/RegionFoodTypes";
                   $("#ConformationDlg").dialog("close");
               }
           },
        {
            text: "No",
            click: function () {
                $("#ConformationDlg").dialog("close");
            }
        }
        ]
    });
}