[英]jQuery if input value is 1 and input is selected
Check the inputs, if value is 1 and is checked, set span color to green, if not, set to red. 检查输入,如果值为1并选中,则将span颜色设置为绿色,否则设置为红色。 I know that I am not selecting the span properly either, I can't figure out how I should do that.
我知道我也没有正确选择范围,我无法弄清楚我应该怎么做。
HTML HTML
<input type="radio"name="rate" value="1" CHECKED>
<span class="radioLabel">Yes</span>
<input type="radio" name="rate" value="0">
<span class="radioLabel">No</span>
jQuery jQuery的
$('.ratingInput input')
.each(function() {
if($(this).val() == ('1') && $(this).is(':selected'))
{
$(this + ('span')).css('border','1px solid green');
} else {
$(this + ('span')).css('border','1px solid red');
}
}
This will do what you want 这将做你想要的
$('input')
.each(function () {
if ($(this).val() == ('1') && $(this).is(':checked')) {
$(this).next('span').css('border', '1px solid green');
} else {
$(this).next('span').css('border', '1px solid red');
}
});
Try 尝试
$(this).next('span').css('border','1px solid green');
$('input:checked[value="1"]').next('span').css('border', '1px solid green'); $('input[value!="1"]').not(':checked').next('span').css('border', '1px solid red');
Working demo http://jsfiddle.net/UL3Cn/ 工作演示 http://jsfiddle.net/UL3Cn/
few things were incorrect: :)
有些事情是不正确的:
:)
})
})
checked
: http://api.jquery.com/checked-selector/ checked
: http : //api.jquery.com/checked-selector/ .next
for span .next
作为span rest should fit the need :)
休息应该适合需要
:)
code 码
$(document).ready(function () {
$('.ratingInput input').each(function () {
if ($(this).val() == ('1') && $(this).is(':checked')) {
$(this).next('span').css('border', '1px solid green');
} else {
$(this).next('span').css('border', '1px solid red');
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.