如果我點擊錯誤函數,如何更改文本框的顏色?我嘗試下面的代碼,但它不工作,只會顯示錯誤消息。使用getElementById更改樣式背景屬性
<Script>
function fnName(ID)
{
var flag = true;
if(document.mainform.NAME.value == "")
{
error_function("Please enter the Name.",ID);
flag = false;
}
else
{
release_function(ID)
flag = true;
}
return flag;
}
function error_function(message,IDs)
{
var ID = '"' + IDs + '"';
document.getElementById("proposererrMsg").innerHTML = message;
document.getElementById("proposererrMsg").style.display = "inline";
document.getElementById(ID).style.background = "#DDDDDD"; //this line not working
document.getElementById(ID).style.border = "thin solid red"; // this line not working
}
</script>
<label id="proposererrMsg" class="errMsg"></label>
<input type="text" name="NAME" id="NAME" value="<%=NAME%>" onblur="fnName(this.id);" />
'.error {背景色:#ddd}'+'的document.getElementById(ID).className = 「錯誤」;' – Andreas