我无法停止 onClick
事件?
如果我只是将 dom 节点与 onclick
事件一起使用,则 dojo.stopEvent()
可以工作,但不能与小部件的 onClick
一起使用。
我收到错误“无法加载页面...状态 0”。我发现在执行 Ajax 调用时刷新页面时会发生这种情况。我正在发布我的代码。
感谢任何帮助
// create a button which will be replaced by the Button widget
var submitButton = dojo.create('button', {type:"submit", id:"submitButton"}, popupFormControlDiv);
var popupFormSubmitButton = new dijit.form.Button({label: "Create", type:"submit"}, "submitButton");
dojo.connect(popupFormSubmitButton, "onClick", function(event) {
//Stop the submit event since we want to control form submission.
event.preventDefault();
event.stopPropagation();
dojo.stopEvent(event);
// construct the arguments for the post request
var xhrArgs = {
form: popupForm,
url: "/admin/sys-config/registration-form/add",
handleAs: "text",
load: function(data) {
console.log("success");
},
error: function(error) {
console.log("error");
}
}
var deferred = dojo.xhrPost(xhrArgs);
});
最佳答案
我刚刚尝试使用小部件和常规按钮,这两种方法都可以让按钮的单击处理程序阻止事件提交表单。
仅限 DOM:http://jsbin.com/inoyo4/edit
小部件:http://jsbin.com/ayomu4/edit
请注意,使用 DOM,我连接到 onclick
,而使用小部件,我连接到 onClick
。 dijit 经常使用驼峰式表示法,并且 dijit 小部件包含许多事件 Hook ,这些事件 Hook 映射到小部件内节点上的标准 DOM 事件(小写)。不幸的是,这可能会引起困惑。
您可能会发现值得一读:http://docs.dojocampus.org/quickstart/events
关于php - 道场 : Unable to stop "onClick" dijit event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3465494/