开发者

javascript ok cancel pop-up button

I've tried a lot of things, but still can access a .js file from inside a form: please, can anyone tell me how it can be done?

this is what I am trying to call:

 <script type="text/java开发者_运维技巧script">
    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>

this is how I've been trying to call:

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

Thank you.


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


You are adding HTML code inside of your JavaScript code. You need to separate them. Something like:

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

would do the trick.


You need to make your code into a javascript function, like this

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

And in the button html:

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


//  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");
            }
        }
        ]
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜