Javascript 仅适用于IE7的onfocus和onblur
我们是否可以为特定浏览器(如IE7)编写事件,例如Javascript 仅适用于IE7的onfocus和onblur,javascript,asp.net,css,Javascript,Asp.net,Css,我们是否可以为特定浏览器(如IE7)编写事件,例如onblur或onfocus 下面是我尝试过的 <asp:TextBox onfocus="this.style.backgroundColor='yellow'" onblur="this.style.backgroundColor='white'" Text="something" ID="txtName" runat="server" ></asp:TextBox> 请注意,这对我来说很好。但我只需要在IE7
onblur
或onfocus
下面是我尝试过的
<asp:TextBox onfocus="this.style.backgroundColor='yellow'" onblur="this.style.backgroundColor='white'" Text="something" ID="txtName" runat="server" ></asp:TextBox>
请注意,这对我来说很好。但我只需要在IE7上执行onblur
和onfocus
可能吗
也许有人曾经面对过这种需要
提前感谢您可以检测浏览器并仅在其为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]-->
它将仅在IE 7中运行!还有,你把代码放在正文的末尾了吗?这对梅来说非常有效。把它放在正文的开头。我应该把它放在正文的末尾吗?当你把它放在head中时,脚本在文本框出现在页面上之前就被执行了,因此把它放在正文中如果你想让它从开头开始工作,把整个代码绑定到window.load。是的,首先,如果你认为这在技术上是好的,那么我会在
结束之前把它放在那里,我的第二个问题/问题是多行文本框在任何浏览器中都不起作用!!!有什么建议吗?