我有一个验证代码,如果输入文本为空白或模糊,我想将输入文本的边框颜色更改为红色。
在 FF 和 Chrome 中,它工作正常。 在 IE10 中,它不起作用。
这是我的脚本
function onblur_style() {
var x = document.forms["myform"]["MySearchKeywordInput"].value;
if (x != "" || x != null) {
document.getElementById("MySearchBox").style="border: 2px solid #5A5A5A;color: red";
}
}
function validateForm() {
var y = document.forms["myform"]["MySearchKeywordInput"].value;
if (y==null || y=="") {
alert("At least one search query is required.");
document.getElementById("MySearchBox").style="border: 2px solid #FF0000;color: red";
return false;
} else {
document.forms["myform"].submit();
}
}
这是我的html
<form id="myform" method="get" action="http://submitpage.page" onsubmit="return validateForm()">
<table>
<tr>
<td>
<input type="text" id="MySearchBox" name="MySearchKeywordInput" maxlength="60" size="180" value="Search for solutions" onfocus="if (this.value==this.defaultValue)this.value='';" onblur="onblur_style()">
</td>
<td>
<input type="image" src="http://image/magnifying_glass.gif">
</td>
</tr>
</table>
有什么想法吗?
最佳答案
正如我在评论中提到的,您似乎将 style
property 与 style
attribute 混淆了。
如果你想使用这个属性,尝试这样的事情......
var searchBoxStyle = document.getElementById("MySearchBox").style;
searchBoxStyle.border = '2px solid #5A5A5A';
searchBoxStyle.color = 'red';
关于javascript - CSS 不适用于 IE - 边框样式更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25615612/