在加载时应用选择bg颜色?

时间:2013-05-15 20:31:37

标签: javascript html css load

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

如何在页面加载时显示bg颜色?

2 个答案:

答案 0 :(得分: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);
}

答案 1 :(得分:2)

<{1>} window.load使用selectbox ID调用该函数..

试试这个

window.onload=function(){
 colourFunction(document.getElementById('select1'));
 colourFunction(document.getElementById('select2'));
};