gpt4 book ai didi

jquery - 在用户输入时清除初始幻影文本并将字体颜色更改为黑色

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:01 25 4
gpt4 key购买 nike

我的页面上有一些文本框,其中的幻影文本在焦点上消失了。我想出了如何在用户输入时将字体更改为黑色,但我无法弄清楚如果用户清除输入的文本框如何将字体颜色设置回银色。

任何帮助将不胜感激

标题中的 Jquery:

$(document).ready(function () {
$('input:text').focus(function () {
$(this).val('');
if ((this).val !== '') {
$(this).css('color', 'black');
}
});
});

CSS:

input[type="text"] {
color: #C0C0C0;
text-align: center;
font-size:18px;
height: 30px;
width: 150px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}

示例文本框标记:

<asp:TextBox
ID="txtLastName"
runat="server"
MaxLength="50"
onblur="if(this.value == ''){ (this.value = 'Last Name';) (this.css ('color', 'silver');)}"
onfocus="if(this.value == 'Last Name'){this.value = '';}"
Text="Last Name">
</asp:TextBox>

最佳答案

您是否尝试过将所有 jQuery onBlur 和 onFocus 放入代码的 jQuery 部分?

$(document).ready(function () {
$('input:text').blur(function () {
if ($(this).val == '') {
$(this).val = "Last Name";
$(this).css('color', 'silver');
}
});
$('input:text').focus(function() {
if($(this).val == 'Last Name') {
$(this).val = "";
$(this).css('color', 'black');
}
});
});

关于jquery - 在用户输入时清除初始幻影文本并将字体颜色更改为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18001743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com