请查看以下链接以查看我的操作代码:
http://codepen.io/DigitalSquid/pen/mAkuC
如何在页面加载时显示bg颜色?
答案 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)
window.load
使用selectbox ID调用该函数..
试试这个
window.onload=function(){
colourFunction(document.getElementById('select1'));
colourFunction(document.getElementById('select2'));
};