以下javascript代碼在Opera(v10.5x)中完美運行,但在Firefox(v3.6)和IE8中失敗。Javascript樣式分配僅適用於Opera(但不適用於Firefox或IE8)
function HighlightBox(elementid,highlight)
{
var hstyle="none";
if (highlight)
{
switch (elementid)
{
case 'emailbox':
case 'lastnamebox':
case 'firstnamebox':
case 'campusbox':
hstyle="width:275px;height:70px;border:2px solid red;";
break;
case 'isdbox':
hstyle="width:275px;height:100px;border:2px solid red;";
break;
}
}
document.getElementById(elementid).style = hstyle;
}
我已經嘗試了個人作業,如:
document.getElementById(elementid).style.width="275px";
...
但這些似乎並沒有擦出火花。
我很感謝在這件事上的任何幫助。 謝謝 艾附註
瀏覽器中是否有錯誤信息? – Billy 2010-06-16 16:21:23
另外,請確保在頁面加載過程中調用該函數。您必須在window.onload事件中調用該函數。否則,你會得到「document.getElementById(elementid)」爲空錯誤 – Billy 2010-06-16 16:27:39