如何使用javascript在文本框中输入文本时按钮图像按钮的颜色 [英] how to chnage color of image button when text entered in textbox using javascript

查看:77
本文介绍了如何使用javascript在文本框中输入文本时按钮图像按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有一个文本框和两个图像按钮,最初图像按钮为蓝色,当文本输入文本框时按钮应更改为红色(其他图像按钮),很快回复,感谢提前

 i have a textbox and two image buttons in form,initially the image button is in blue color when the text is entered in the textbox the button should change to redcolor(other image button),reply soon,thanks on advance

推荐答案

您好,

请找到您的答案。我使用过jQuery ---

Please find your answer. I have used jQuery---

< input type =" text" id =" txt" />

< input type =" button"名称= QUOT;试验" ID = QUOT; BTN2" value ="按钮2" style =" background-color:blue" />

< script type =" text / javascript">

    jQuery(document).ready(function(){

        jQuery(" #txt")。keyup(function(){

            if(jQuery(this).val()。length> 0)


                jQuery(" #btn2")。css(" background -color"," red");&
            else

  ;               jQuery(" #btn2")。css(" background-color"," blue" ;);

       });

   });

< / script>

<input type="text" id="txt"/>
<input type="button" name="test" id="btn2" value="Button 2" style="background-color:blue"/>
<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery("#txt").keyup(function() {
            if (jQuery(this).val().length > 0)
                jQuery("#btn2").css("background-color", "red");
            else
                jQuery("#btn2").css("background-color", "blue");
        });
    });
</script>


这篇关于如何使用javascript在文本框中输入文本时按钮图像按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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