Jquery 当文本框为空时如何更改文本框的边框颜色丢失焦点事件和onfocus事件如果文本不为空则不更改边框颜色
如果文本框为空,我想使用事件更改文本框的边框颜色 jsJquery 当文本框为空时如何更改文本框的边框颜色丢失焦点事件和onfocus事件如果文本不为空则不更改边框颜色,jquery,Jquery,如果文本框为空,我想使用事件更改文本框的边框颜色 js $(document).ready(function () { $("#name1").onFocus(function () { if ($("#name1").val() == "") $(this).css({ "border": "red", }); $("#name1").LostFocus(function () { if (
$(document).ready(function () {
$("#name1").onFocus(function () {
if ($("#name1").val() == "") $(this).css({
"border": "red",
});
$("#name1").LostFocus(function () {
if ($("#name1").val() != "") $(this).css({
"border": "",
});
});
});
});
.red {
border-color:red;
}
HTML
<form action="">
<input id="name1" type="textbox"></input>
<input id="name2" type="textbox"></input>
<input id="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
<form action="">
<input id ="name1" type="textbox"></input>
<input id ="name2" type="textbox"></input>
<input id ="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
尝试聚焦
而不是聚焦
,并使用模糊
进行失焦
$(document).ready(function() {
$("#name1").focus(function(){
if ($("#name1").val() == "")
$(this).css({
"border": "red",
});
$("#name1").blur(function(){
if ($("#name1").val() != "")
$(this).css({
"border": "",
});
});
});
阅读更多:和尝试
focus
而不是onFocus
,并使用blur
进行LostFocus
$(document).ready(function() {
$("#name1").focus(function(){
if ($("#name1").val() == "")
$(this).css({
"border": "red",
});
$("#name1").blur(function(){
if ($("#name1").val() != "")
$(this).css({
"border": "",
});
});
});
阅读更多:和尝试
focus
而不是onFocus
,并使用blur
进行LostFocus
$(document).ready(function() {
$("#name1").focus(function(){
if ($("#name1").val() == "")
$(this).css({
"border": "red",
});
$("#name1").blur(function(){
if ($("#name1").val() != "")
$(this).css({
"border": "",
});
});
});
阅读更多:和尝试
focus
而不是onFocus
,并使用blur
进行LostFocus
$(document).ready(function() {
$("#name1").focus(function(){
if ($("#name1").val() == "")
$(this).css({
"border": "red",
});
$("#name1").blur(function(){
if ($("#name1").val() != "")
$(this).css({
"border": "",
});
});
});
阅读更多信息:并使用自定义onChange处理程序:
使用自定义onChange处理程序:
使用自定义onChange处理程序:
使用自定义onChange处理程序:
使用模糊尝试此操作
$("input[type='textbox']").blur(function () {
var text = $(this).val();
if(text == "")
{
$(this).css('border-color','red');
}
});
小提琴:使用模糊试试这个
$("input[type='textbox']").blur(function () {
var text = $(this).val();
if(text == "")
{
$(this).css('border-color','red');
}
});
小提琴:使用模糊试试这个
$("input[type='textbox']").blur(function () {
var text = $(this).val();
if(text == "")
{
$(this).css('border-color','red');
}
});
小提琴:使用模糊试试这个
$("input[type='textbox']").blur(function () {
var text = $(this).val();
if(text == "")
{
$(this).css('border-color','red');
}
});
小提琴:试试这个
现场观看
HTML
<form action="">
<input id="name1" type="textbox"></input>
<input id="name2" type="textbox"></input>
<input id="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
<form action="">
<input id ="name1" type="textbox"></input>
<input id ="name2" type="textbox"></input>
<input id ="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
jQuery
$(document).ready(function() {
$("input").focusin(function(){
if ($(this).val() == "")
$(this).addClass("red")
});
$("input").focusout(function(){
if ($(this).val() != "")
$(this).removeClass("red")
});
});
试试这个
现场观看
HTML
<form action="">
<input id="name1" type="textbox"></input>
<input id="name2" type="textbox"></input>
<input id="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
<form action="">
<input id ="name1" type="textbox"></input>
<input id ="name2" type="textbox"></input>
<input id ="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
jQuery
$(document).ready(function() {
$("input").focusin(function(){
if ($(this).val() == "")
$(this).addClass("red")
});
$("input").focusout(function(){
if ($(this).val() != "")
$(this).removeClass("red")
});
});
试试这个
现场观看
HTML
<form action="">
<input id="name1" type="textbox"></input>
<input id="name2" type="textbox"></input>
<input id="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
<form action="">
<input id ="name1" type="textbox"></input>
<input id ="name2" type="textbox"></input>
<input id ="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
jQuery
$(document).ready(function() {
$("input").focusin(function(){
if ($(this).val() == "")
$(this).addClass("red")
});
$("input").focusout(function(){
if ($(this).val() != "")
$(this).removeClass("red")
});
});
试试这个
现场观看
HTML
<form action="">
<input id="name1" type="textbox"></input>
<input id="name2" type="textbox"></input>
<input id="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
<form action="">
<input id ="name1" type="textbox"></input>
<input id ="name2" type="textbox"></input>
<input id ="name3" type="textbox"></input>
<input type="button" value="submit"></input>
</form>
jQuery
$(document).ready(function() {
$("input").focusin(function(){
if ($(this).val() == "")
$(this).addClass("red")
});
$("input").focusout(function(){
if ($(this).val() != "")
$(this).removeClass("red")
});
});
尝试
focus
而不是onFocus
,对LostFocus
使用blur
。尝试focus
而不是onFocus
并对LostFocus
使用blur
并对LostFocus
使用blur
。尝试focus对于LostFocus
使用blur
,而不是onFocus
。