Javascript 如何从按钮点击条件后面的代码调用java脚本函数?
我想打开一个模型弹出在一些按钮点击代码背后,有一些如果其他条件。首先,我无法确定什么是最好的方法。 我认为我的选择如下。 1) 调用jquery模型弹出窗口 2) ajax模型弹出窗口Javascript 如何从按钮点击条件后面的代码调用java脚本函数?,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我想打开一个模型弹出在一些按钮点击代码背后,有一些如果其他条件。首先,我无法确定什么是最好的方法。 我认为我的选择如下。 1) 调用jquery模型弹出窗口 2) ajax模型弹出窗口 function xyz() { // alert('hi tpo all'); // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
这是一个按钮,固定在一些按钮点击条件打开模型弹出窗口,如果模型弹出窗口说是的话,我想让客户重拨到某个付款页,他将支付购买项目
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
现在我正在使用Jquery模型弹出窗口
我这样称呼他
protected void imgClientFreeEval_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
-----
---some code not typed
if (SurveyCount > 1)
{
Session["YourAssessment"] = true;
Session["MyAssessment"] = false;
ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", "<script>xyz()</script>", true);
//Response.Redirect("~/yourAssessment.aspx");
}
}
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$(document).ready(function () {
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
现在的问题是这个函数根本没有被调用。这有什么问题,我辛苦了很长时间,如果可能的话,请建议我最好的方法,我应该如何执行它。
我无法从代码隐藏按钮单击调用此javasccipt函数。我用于从代码隐藏中获取javascript警报的方法如下:
public void AMessage(string message)
{
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "info only", "alert('" + message + "');", true);
}
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
如果您没有在按钮中使用OnClientClick事件,则通过类似的处理程序发送消息。在您的情况下,不要调用
“alert”(“+message+”);“
调用您编写的函数。尝试使用以下方法:
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
如果您希望获得警报,然后在单击“确定”时重定向页面。您可以尝试以下方式:
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
ClientScript.RegisterStartupScript(this.GetType(), "My alert", "alert('" Your time has been finished "');", true);
System.Text.StringBuilder sbs = new System.Text.StringBuilder();
sbs.Append("<script language='javascript'>");
sbs.Append("window.location = 'http://www.google.com/'");//or whatever you want:-
sbs.Append("</script>");
Type tr = this.GetType();
ClientScript.RegisterClientScriptBlock(tr, "PopupScript2", sbs.ToString());
ClientScript.RegisterStartupScript(this.GetType(),“我的警报”,“警报(““您的时间已经结束”);”,true);
System.Text.StringBuilder sbs=新的System.Text.StringBuilder();
sbs.追加(“”);
sbs.Append(“window.location=”http://www.google.com/'");//或者你想要什么:-
sbs.追加(“”);
类型tr=this.GetType();
RegisterClientScriptBlock(tr,“PopupScript2”,sbs.ToString());
我在您的代码中指出的一个问题是:
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", "<script>xyz()</script>", true);
ScriptManager.RegisterStartupScript(this,this.GetType(),“tmp”,“xyz(),true);
您正在将最后一个参数作为true传递,它是addScriptTags,但您已经在调用中添加了脚本标记,因此可能是它在那里造成了问题
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}
干杯哪个函数没有被调用??函数xyz(),我只想做一个警报类的事情,它会在“是”和“否”的条件下修复重定向。正如您所提到的,我可以这样做警报,如果“确定”,然后重定向到某个页面,如果“取消”,然后重定向到另一个页面吗?我没有使用onclientclickkno,这是您不能使用的原因。正如您所做的,您已经在代码背后构建了脚本,如果您使用的是确认,那么javascript事件处理应该能够以正常方式重定向。只需在您传递给ScriptManager的脚本中处理来自确认的响应。不过,要添加到这一点,请确保脚本管理器参数中的所有分号等都正确-很容易删除分号。就我个人而言,我会考虑在另一种方法中将脚本构造为字符串,将脚本作为字符串变量获取,然后将该变量传递给ScriptManager。我只是不明白,我已经辛苦了很长时间了你有没有设法调试你想要运行的实际脚本?例如,将其拉入自己的.js文件,并使用提供的参数运行它。确保基本脚本正常工作,然后在此基础上进行构建。我希望有ok Cancle之类的功能,我只能在模型中弹出,我想,在取消时,我想重定向到其他页面。同样的方法,你也可以这样做。
function xyz() {
// alert('hi tpo all');
// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
// $("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
resizable: false,
height: 140,
modal: true,
autoOpen: false,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location.replace("http://stackoverflow.com");
},
Cancel: function () {
window.location.replace("http://stackoverflow.com");
$(this).dialog("close");
}
}
});
});
}