dojo.addOnLoad(Function fn)
Sooner or later,every Javascript programmer tries something like this:
if (dayOfWeek == "Sunday" ){
document. musicPrefs. other. value = "Afrobeat";
}
</script>
<form name= "musicPrefs">
<input type= "text" name= "other">
...
It doesn't work because the "other" control is not defined yet. You can move the code to the bottom of the page,but that removes the linear nature of HTML. If you're reading the code,you want to zero in on a control,and see the code that influences it close by.
dojo.addOnLoad(...) defers script execution until all the HTML is loaded. So this code:
document. musicPrefs. other. value= "Afrobeat";
}
dojo. addOnLoad (setAfrobeat );
conveniently replaces the one above. When the function is small,you may prefer to write it inline:
function (){
document. musicPrefs. other. value= "Afrobeat";
}
);
This is the function literal or anonymous function construct of JavaScript. If it looks really,really wierd to you,take a peek ahead at Functions as Variables for an explanation.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。