我正在使用这样的jquery分配点击处理程序,以切换按钮的功能
$(function () {
$(".ButtonReorder").click(
function () {
//USER STARTS REORDERING - BUTTON CHANGES TO "SAVE" AND "CANCEL" BUTTON APPEARS
if ($(this).attr("value") === "Reorder Images") {
...
}
//USER SUBMITS NEW ORDER - REORDERING GETS DISABLED
else {
...
}
}
);
现在,我们正在从 html 文字控件更改为 ASP.Net 控件。它被退回,这是我们不想要的。我看到有人在 OnClientClick 函数中提到 return false。因此,我尝试通过 OnClientClick 分配 JS 函数而不是 jQuery,就像这样,但意识到这个关键字现在不指代按钮。我如何引用它?
//代码后面
Button reorderButton = new Button();
reorderButton.CssClass = "ButtonReorder";
reorderButton.Text = "Reorder Images";
reorderButton.OnClientClick = "return reorderClick();";
//JS代码
function reorderClick() {
//USER STARTS REORDERING - BUTTON CHANGES TO "SAVE" AND "CANCEL" BUTTON APPEARS
if ($(this).attr("Text") === "Reorder Images") {
$(this).attr("value", "Save New Order"); //change button to show "Save New Order" from "Reorder Images"
...
return false; //starting reorder, don't want to submit;
}
//USER SUBMITS NEW ORDER - REORDERING GETS DISABLED
else {
$(this).attr("value", "Reorder Images"); //set button back to original "Reorder Images" from "Save New Order"
...
return true; //done reordering, submit;
}
}
但这不是指按钮。OnClientClick 不会将操作对象传递给处理程序吗?有没有办法通过?
谢谢, Ozgur Ozturk