如果文本框达到一定数量,如何更改它的背景颜色? [英] How to change the background color of a textbox if it reaches of a certain number?

查看:126
本文介绍了如果文本框达到一定数量,如何更改它的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上标题,我希望文本框在0以上时为绿色,在0以下时为红色



我尝试了什么:



尝试做一个if语句,显然做错了。

Basically the title, I want the textbox to be green when above 0 and red when below 0

What I have tried:

Tried doing a if statement, apparently doing it wrong.

推荐答案

因为文本框中的文本可以从某处复制并使用鼠标粘贴,我会使用以下内容:



Because texts in the textbox can be copied from somewhere and pasted using the mouse, I would use the following:


#TextBoxID)。bind(' input propertychange' function (){
var textLen = this .value.length;

if (textLen> 0
// 使其绿色
else
// 将其设为红色
});
("#TextBoxID").bind('input propertychange', function () { var textLen = this.value.length; if(textLen > 0) //Make it green else //Make it Red });


这篇关于如果文本框达到一定数量,如何更改它的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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