2

请查看以下链接以查看我的代码:http:
//codepen.io/DigitalSquid/pen/mAkuC

如何使 bg 颜色出现在页面加载中?

4

2 回答 2

2

在加载时调用colourFunction()每个选择:

function initialColours() {
  colourFunction(document.getElementById('select1'));
  colourFunction(document.getElementById('select2'));
};

if (window.addEventListener) {
  window.addEventListener('load', initialColours, false);
}
// older IE versions have a non-standard variant, use that
else if (window.attachEvent) {
  window.attachEvent('onload', initialColours);
}
于 2013-05-15T20:41:19.697 回答
2

使用window.load选择框ID调用该函数..

试试这个

window.onload=function(){
 colourFunction(document.getElementById('select1'));
 colourFunction(document.getElementById('select2'));
};
于 2013-05-15T20:51:12.003 回答