加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dojo.addOnLoad

发布时间:2020-12-16 22:07:24 所属栏目:百科 来源:网络整理
导读:dojo.addOnLoad(Function fn) Sooner or later,every Javascript programmer tries something like this: script if ( dayOfWeek == "Sunday" ) { document. musicPrefs . other . value = "Afrobeat" ; } /script form name = "musicPrefs" input type= "te

dojo.addOnLoad(Function fn)

Sooner or later,every Javascript programmer tries something like this:

<script>
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:

function setAfrobeat (){
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:

dojo. addOnLoad (
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读