您可以检测浏览器并仅在 IE7 时运行您的脚本
把它放在你的标记正文标签的末尾
<!--[if lte IE 7]>
<script type="text/javascript">
var txtBox = document.getElementById('<%= txtName.ClientID %>');
txtBox.onfocus =function(){ txtBox.style.backgroundColor='yellow';};
txtBox.onblur=function(){txtBox.style.backgroundColor='white';};
</script>
<![endif]-->
或者把这个放在头上
<!--[if lte IE 7]>
<script type="text/javascript">
window.onload=function(){
var txtBox = document.getElementById('<%= txtName.ClientID %>');
txtBox.onfocus =function(){ txtBox.style.backgroundColor='yellow';};
txtBox.onblur=function(){txtBox.style.backgroundColor='white';};
}
</script>
<![endif]-->