为什么Google Chrome浏览器没有初始页面焦点将输入字段更改为“绿色”? [英] Why doesn't initial page focus change input field to Green on Google Chrome?

查看:130
本文介绍了为什么Google Chrome浏览器没有初始页面焦点将输入字段更改为“绿色”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在Google Chrome浏览器中,初始页面焦点不会将输入字段更改为绿色?我可能不得不挖掘rgb的东西,不是吗?

 < html> 
< head>
< script src =jquery-1.6.2.js>< / script>

< script type =text / javascript>

函数更改(obj,evt){

if(evt.type ==focus){
obj.style.borderColor =black;
obj.style.backgroundColor =#90EE90; //在聚焦点亮绿色
}
else if(evt.type ==blur){
obj.style.borderColor =white;
obj.style.backgroundColor =#7AC5CD; //(浅蓝色)模糊
}
}

jQuery(document).ready(function(){
jQuery(#Txt1)。focus() ;
});

< / script>

< style type =text / css>

.InputField
{
颜色:黑色;
font-size:12px;
font-weight:bold;
背景颜色:#7AC5CD;
}

< / style>

< / head>

< body>


$ b $ lt; input id =Txt1runat =serverclass =InputFieldonfocus =Change(this,event)onblur =Change(this ,event)/>< br />
< input id =Txt2runat =serverclass =InputFieldonfocus =Change(this,event)onblur =Change(this,event)/>< br /> gt ;
< input id =Txt3runat =serverclass =InputFieldonfocus =Change(this,event)onblur =Change(this,event)/>< br /> ;

< / body>
< / html>

================



2011年8月8日更新



对不起,我对此没有足够的了解。我会写更多的细节的新问题..通过只是改变我的初始代码使用jQuery代码,我可以得到它的工作。在我发布包含绿色和谷歌浏览器的问题之后,我会对每个人进行投票,并将其标记为答案,因为您在第一轮时都非常有帮助。这样你会立即得到通知,并可以开始真正的应用程序代码我的实际问题。下一个将会更艰难。 : - )

早期提示==>如果我在设置焦点之前放一个alert,或者用jQuery调用.focus(),然后在JavaScript Alert上单击OK,它变成绿色。如果我离开警报消息,背景颜色不会变成绿色。



================ ===



8/9/2011更新



问一个新问题:

为什么页面jQuery.focus事件在重定向后将Google Chrome浏览器的背景颜色风格改为绿色? 解决方案

Change函数的范围似乎存在问题。查看这个JS小提琴作为一个工作示例。


Why doesn't initial page focus doesn't change input field to Green on Google Chrome? I probably have to dig up the rgb stuff, don't I?

<html>
<head>
<script src="jquery-1.6.2.js"></script>

    <script type="text/javascript">

        function Change(obj, evt) {

            if (evt.type == "focus") {
                obj.style.borderColor = "black";
                obj.style.backgroundColor = "#90EE90";  // light green on focus
            }
            else if (evt.type == "blur") {
                obj.style.borderColor = "white";
                obj.style.backgroundColor = "#7AC5CD";  // light blue on blur
            }
        }

        jQuery(document).ready(function() {
            jQuery("#Txt1").focus();
        });

    </script>

    <style type="text/css">

    .InputField
    {
        color: black;
        font-size: 12px;
        font-weight: bold;
        background-color: #7AC5CD;
    }

    </style>

</head>

<body>



<input id="Txt1" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
<input id="Txt2" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />
<input id="Txt3" runat="server" class="InputField" onfocus="Change(this, event)" onblur="Change(this, event)" /><br />

</body>
</html>

================

8/8/2011 update

Sorry I wasn't specific enough on this one. I will write a new question with more details.. by just changing my initial code to use jQuery code, I can get it to work. I'll up-vote everyone and mark someone's as the answer just after I post my question containing "Green" and "Google Chrome" since you were all so helpful in the first round. That way you'll be notified immediately and can begin working on my actual question with real application code. The next one will be a little tougher. :-)

Early clue ==> If I put an alert in just before setting focus or calling .focus() with jQuery, and click OK on the JavaScript Alert, it turns green. If I leave the Alert message out, the background-color doesn't change to green.

===================

8/9/2011 update

Asked a new question:

Why isn't page jQuery .focus event changing background-color style to green in Google Chrome after redirect?

解决方案

There seems to be an issue with scope of the Change function. See this JS fiddle for a working example.

这篇关于为什么Google Chrome浏览器没有初始页面焦点将输入字段更改为“绿色”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆