我正在尝试将标志变量传递到节点,在该节点中验证标志是否为真,然后执行dojo.connect(标志,onclick,回调)。其他的则跳过回调函数。
最佳答案
本质上,节点是组成HTML的每个元素的DOM对象表示。
看一下Dojo Toolkit官方文档中的功能:
https://dojotoolkit.org/reference-guide/1.10/dojo/connect.html
您尚未指定,但我想您在1.6中使用Dojo,这是一种古老的做法,因为我们已在其结构功能中实现了AMD架构,您必须具有以下内容:
// Saving your handle
var handle = dojo.connect(node, "onclick", callback);
// Removing the handle
dojo.disconnect(handle);
当您使用
dojo.connect(flag, onclick, callback)
时,我们假设您有一个元素,即DOM节点(在本例中为“标志”)。在Dojo 1.6版本或更旧的版本中,您可以通过其ID来获取节点,例如:(某些官方文档:https://dojotoolkit.org/api/#dojo.byId)
// Here's your node (by ID)
var my_node = dojo.byId("foo");
希望它对您的理解有所帮助。
你需要这样的东西吗?
// Your custom callback
function your_callback_function() {
// You business rules, in this case:
if (dojo.query('#your_flag:checked')) {
// Do something..
}
}
// binding event to the DOM-node and callback
var handle = dojo.connect(dojo.byID("your_flag"), "onclick", your_callback_function);
您可以在https://dojotoolkit.org/reference-guide/1.6/dojo/index.html#events中查看有关
我建议您对AMD和Dojo的新功能有所了解,因为它已经发生了变化。