<script type="text/javascript">
$(document).ready(function() {
$('#gender').change(function() {
if($(this).find('option:selected').val() == 'Male' && $('#size').find('option:selected').val() == 'Large') {
$('#results').val() == 'Size Large - The Most Basic Size'
}
else if($(this).find('option:selected').val() == 'Female' && $('#size').find('option:selected').val() == 'Large') {
$('#results').val() == 'Size Large - The Second Most Basic Size'
}
else {
$('#results').val() == 'Nothing'
};
});
});
</script>
目标很简单:检查两个选择框的值并使用第一个选择更改函数更改#results 输入中的值。这可能非常简单,但我知道我做错了,因为它不起作用....;)
最佳答案
您以错误的方式设置了结果值。试试这个:
<script type="text/javascript">
$(document).ready(function() {
$('#gender').change(function() {
if($(this).find('option:selected').val() == 'Male' && $('#size').find('option:selected').val() == 'Large') {
$('#results').val('Size Large - The Most Basic Size');
}
else if($(this).find('option:selected').val() == 'Female' && $('#size').find('option:selected').val() == 'Large') {
$('#results').val('Size Large - The Second Most Basic Size');
}
else {
$('#results').val('Nothing');
};
});
});
</script>
关于javascript - 更正 jQuery 语法 : Checking two select box option values and writing a separate input value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12900430/