Dojo 事件未触发
我有一个 Dojo 选项卡容器,当我单击某些按钮时,会动态添加一个新选项卡,其内容是通过 Ajax 下载的。这些选项卡包含动态表单元素,Dojo 可以很好地解析和加载这些元素。我还包括特定于每个选项卡的 Javascript 块,并且这些块也通过 Ajax 下载...但是,没有一个 Javascript 块执行!
选项卡内容示例:
<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox" />
<script type="text/javascript">
dojo.connect(dijit.byId('test'), 'onClick', function(evt){
alert('testing 123');
});
</script>
但是,如果我这样做,事件触发就好了:
<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox">
<script type="dojo/method" event='onClick'>
alert('testing 123');
</script>
</input>
我的问题是,为什么第一个示例中的 Javascript 块不起作用?这是 Dojo 的限制吗?另外,我还尝试在加载小部件后设置它们的属性和值。鉴于我必须使用诸如 dojo.addOnLoad()
之类的东西,我该如何激活它,它不起作用,因为它需要一个 Javascript 块,并且按照第一个示例不起作用......没有等效的小部件 onLoad 事件,所以我也不能使用第二种方法...有什么想法可以做到这一点吗?
I have a Dojo tab-container and when I click on certain buttons, a new tab is added dynamically with its contents downloaded via Ajax. The tabs contain dynamic form elements which are parsed and loaded by Dojo just fine. I am also including Javascript blocks which are specific for each tab and those are downloaded as well via Ajax... however, none of the Javascript blocks execute!
Example of tab content:
<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox" />
<script type="text/javascript">
dojo.connect(dijit.byId('test'), 'onClick', function(evt){
alert('testing 123');
});
</script>
However, if I do this instead the events trigger just fine:
<input id="test" name="test" type="text" dojoType="dijit.form.ValidationTextBox">
<script type="dojo/method" event='onClick'>
alert('testing 123');
</script>
</input>
My question is, why don't Javascript blocks in the first example work? is this a Dojo limitation? Also, I am also trying to set properties and values for the widgets AFTER they've been loaded. How do i active that given I have to use something like dojo.addOnLoad()
which won't work because it requires a Javascript block and that doesn't work as per the first example... There is no equivalent widget onLoad event so I can't use the second method either... Any ideas how to go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“选项卡内容”实际上是一个内容窗格元素。除非使用
,否则无法在内容窗格内调用 javascript。至少这是我所知道的。
更新:如果您使用
dojox.layout.ContentPane
而不是dijit.layout.ContentPane
,所有与其中的js有关的问题都会消失。来自 Dojo 参考指南:The "tab content" is actually a Content Pane element. You can't call a javascript inside a content pane unless you use
<script type="dojo/method">
. At least this is what I know.Update: ifyou'll use
dojox.layout.ContentPane
instead of thedijit.layout.ContentPane
all the problems regarding the js inside it will vanish. From Dojo Reference Guide:看起来您需要使用 dojo.hitch 以便您的函数在实际调用时位于范围内。尝试使用:
您可以在这里阅读更多相关信息:http://dojotoolkit。 org/reference-guide/dojo/hitch.html#dojo-hitch
It looks like you need to use dojo.hitch so that your function will be in scope when it is actually called. Try using:
You can read more about it here: http://dojotoolkit.org/reference-guide/dojo/hitch.html#dojo-hitch
您必须确保首先解析该小部件。这样做:
You have to ensure that the widget has been parsed first. Do it like so :