说我有下面的代码,当有人单击汽车名称时,我想激活我的按钮,但是我不想写每个汽车名称。我想使用属性“ ^ =“,当有人选择汽车制造商法拉利,菲亚特或福特时,允许我激活按钮。在CSS中,它们存在属性“ ^ =” witch,我可以使用它来定义名称的第一个字符-在我的示例中,“ f”用于具有第一个字符的汽车。当我在我的jquery代码中写入此属性时,代码不起作用。有谁知道我可以在下面的代码中定义CSS属性“ ^ =”吗?
我尝试编写代码[value ^ =“ f”],但它不起作用。
html
<select class="cars">
<option value="none" selected></option>
<option value="ferrari">Ferrari</option>
<option value="fiat">Fiat</option>
<option value="ford">Ford</option>
</select>
<button class="SubmitButton" type="button" >Click Me!</button>
的CSS
.SubmitButton {width:150px;}
.ButtonColor1 {color:red;}
:disabled {
border:3px solid lightgray;
color:gray;
}
button {
border:3px solid green;
color:black;
}
button:hover:disabled {
cursor:not-allowed;
}
button:hover {
cursor:pointer;
}
jQuery的
$(document).ready(function() {
if($("select.cars").val() == "none"){
$(".SubmitButton").attr("disabled", "disabled");
}
$("select.cars").change(function(){
if($(this).val() == [value^="f"]){
$(".SubmitButton").removeAttr("disabled");
$(".SubmitButton").addClass("ButtonColor1");
}
else if($("select.cars").val() == "none"){
$(".SubmitButton").attr("disabled", "disabled");
}
});
});
相关分类