【发布时间】:2018-01-26 04:56:56
【问题描述】:
点击提交按钮后如何选择input:empty和input:not(:empty)值并添加以下条件:
-
如果值为空,点击后改变背景颜色。
(正如您在 输入 Text3 中看到的那样,它不起作用)
-
如果值不为空,点击后添加这三个条件:
(在我的示例代码中不起作用)
• {光标:不允许;} • 只读 • 更改背景颜色
这是我的示例代码:
$(".signupbtn").on('click', function() {
$("input").filter(function() {
return this.value.length !== 0;
}).val("Successfully Received!");
$("input:empty")
.css("background", "rgb(255,220,200)");
$("input:not(:empty)").style.cursor = "not-allowed";
$("input:not(:empty)")
.css("background", "rgb(220,20,60)");
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form action="" method="POST" onsubmit="return false;">
<input class="form-control" type="text" placeholder="" name="firstname" value="">
<input class="form-control" type="text" placeholder="" name="firstname" value="">
<input class="form-control" type="text" placeholder="" name="firstname" value="sss">
<button type="submit" class="signupbtn">Sign Up</button>
</form>
【问题讨论】:
-
您已经在正确使用
.css。现在阅读控制台中的错误并更正它。
标签: javascript jquery