这是html / jquery im正在进行
<form>
<select>
<option>Please Select Your Value</option>
<option>Pick this value 1</option>
</select>
<div class="error">Please select your value</div>
<select>
<option>Please Select Your Value</option>
<option>Pick this value 2</option>
</select>
<div class="error">Please select your value</div>
<input type="submit" value="Show Hidden Div" />
</form>
<div class="suprise">
Hidden Div
</div>
和jQuery
$('.submit').click(function(){
var correct = true;
$('select').each(function(){
if($(this).val() != 'option2value'){
//next is the error... it might be better to use an id there
$(this).next().show();
correct = false;
}
})
if(correct){
$(".results").animate({
marginTop: -480}, 400);
}
})
我只需要一点帮助,如何做出正确的触发......我不知道该怎么做。
谢谢你们!
答案 0 :(得分:0)
首先,您需要在select
<select id="select1">
<option>Please Select Your Value</option>
<option>Pick this value 1</option>
</select>
<div class="error">Please select your value</div>
<select id="select2">
<option>Please Select Your Value</option>
<option>Pick this value 2</option>
</select>
$("select[id^=select]").on("change", function() {
if ($(this).attr("id") == "select1") {
if ($(this).val() == $("#select2").val()) {
alert("You are wrong");
} else {
alert("You are right");
}
}
else {
if ($(this).val() == $("#select1").val()) {
alert("You are wrong");
} else {
alert("You are right");
}
}
})
答案 1 :(得分:0)