【问题标题】:onChange select list [duplicate]onChange 选择列表 [重复]
【发布时间】:2014-07-21 16:17:15
【问题描述】:
<form name="storelocator_cities_form" id="storelocator_cities_form">
    <select name="storelocator_city" id="storelocator_city" onchange="storeLocatorForm.fetchStoresByCountryAndPostCode(this)">
         <option value=""></option>
    </select>
</form>

您好,我想捕获选项值,然后将其与特定城市进行比较,但我被卡住了。我是 JS 和 jQuery 的新手,但我想我需要做类似的事情

jQuery(function(){
    $('#storelocator_city').on('change',function(){
        var city = $(this).val();
    });
});

我想要一种方法来查看我在控制台的 var 中获得了正确的值。

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    我想要一种方法来查看我在 var 中获得了正确的值 控制台

    当然,但首先:

    为什么你有 2 个 onchange 事件?

    无论如何 - 在控制台中查看值:试试这个:

    jQuery(function(){
         $('#storelocator_city').on('change',function(){
           var city = $(this).val();
           console.log(city); <------- Try this
        });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      相关资源
      最近更新 更多