我知道我的标题有点混乱,也许有人可以提出不同的建议。
所以无论如何,我正在学习一些 Jquery,我想用它来进行表单验证,我会展示代码然后问这个问题。
形式:
<form action="" method="POST">
<ul>
<li>
<label for="market_1">Market: </label>
<input type="text" name="market_1" id="market_1" />
</li>
</ul>
</form>
JS:
$(document).ready(function()
{
$("#market_1").addClass("text_box_error");
});
CSS:
input[type="text"]
{
background-color: rgba(255, 255, 255, 0.5);
border: 1px solid #5B5B5B;
width: 148px;
}
input[type="text"]:hover, input[type="text"]:focus
{
background-color: rgba(255, 255, 255, 1);
border: 1px solid #5B5B5B;
font-weight: bold;
}
.text_box_error
{
background-color: red;
}
目前,我只是想让它在单击提交按钮时改变颜色。现在我可以让它工作,但是当我input[type="text"]
用来设置输入框的样式时我不能让它工作。
我想通过这样做,我可以将所有输入框的样式设置为相同,然后使用 jquery addClass 方法我可以覆盖背景颜色。
那么,为什么这不适用于我向您展示的设置?
编辑:对不起,我已经更新了代码并在这里粘贴了错误的版本,我没有更新代码。