javascript - 更正 jQuery 语法 : Checking two select box option values and writing a separate input value

标签 javascript jquery syntax

<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/

相关文章:

javascript - 在 React js 中传递多个 Prop 的最佳方法

javascript - EmberJS jQuery 弃用和基础

c++ - 将二维数组传递给 C 和 C++ 中的函数

javascript - 这个 JavaScript/jQuery 语法如何工作 : (function( window, undefined ) { })(window)?

html - 父DIV中的高度不同

javascript - 单击页面上的其他任何位置时如何停止 jQuery .focus() 函数

javascript - updatepanel 更新后如何调用 javascript 函数

javascript - 在井内悬停时向 Bootstrap 缩略图图像添加叠加层

jquery错误放置

javascript - Function.prototype.propertyname === Object.propertyname 是真的吗?