简体   繁体   English

在onload上将值设置为选择框的问题

[英]Issues setting a value to a select box on the onload

I'm having issues setting a value to a select box when loading the page. 加载页面时,将值设置为选择框时遇到问题。 On the onload I parse the URL for variables and after that I have to set the values retrieved from the url to a specific select box. 在onload上,我解析变量的URL,然后必须将从url检索的值设置为特定的选择框。 The problem is when I'm trying to set the value using dijit: 问题是当我尝试使用dijit设置值时:

dijit.byId("assettypeselect").set('value',queryObject.assettypeselect);

an error occurs because dijit library is not loaded yet. 发生错误,因为尚未加载dijit库。 I've used dojo.addOnLoad and dojo.ready, but none of those work. 我使用过dojo.addOnLoad和dojo.ready,但是这些都不起作用。 Is there another eventhandler I can use that waits until all libraries are loaded or in what other way can I work to solve this. 我可以使用另一个事件处理程序来等待,直到所有库都加载完毕,或者可以通过其他方式解决该问题。

Thanks for your time! 谢谢你的时间!

A likely solution, based off the limited information you've provided, is to wait for the window 's load event to fire. 根据您提供的有限信息,一种可能的解决方案是等待windowload事件触发。 If dijit is still undefined have a look in your console and check to make sure the external/internal library is being requested properly. 如果dijit仍未undefined请在控制台中查看并检查以确保正确请求了外部/内部库。 Also, if dijit is being loaded AMD style, make sure you've referenced it as a dependency . 另外,如果dijit正在加载AMD样式,请确保已将其引用为依赖项

window.addEventListener('load', function(){
    dijit.byId("assettypeselect").set('value',queryObject.assettypeselect);
}, false);

The load event fires at the end of the document loading process. 加载事件在文档加载过程结束时触发。 At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading. 至此,文档中的所有对象都在DOM中,并且所有图像,脚本,链接和子框架均已完成加载。

https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload#Notes https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload#Notes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM