用jQuery检测任何选定的下拉值? [英] detecting any selected dropdown value with jquery?

查看:128
本文介绍了用jQuery检测任何选定的下拉值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能可以检测所有输入值与keyup的变化:

I have a function that detects all input value changes with keyup:

jQuery:

// detect all inputs

$('.inputChange').each(function() {
   // Save current value of element
   $(this).data('oldVal', $(this).val())

   // Look for changes in the value
   $(this).bind("propertychange keyup input paste", function(event){
      // If value has changed...
      if ($(this).data('oldVal') != $(this).val()) {
       // Updated stored value
       $(this).data('oldVal', $(this).val())
        currentVal = $(this).val()
       // Do action
       inputElement = $(this).attr('data-element')
       inputProperty = $(this).attr('data-property')
       inputUnit = $(this).attr('data-unit')
        updateAllCSS(inputElement, inputProperty, currentVal + inputUnit)
     }
   });
 });

HTML:

    <input class="inputChange" data-element=".homeTemplate #colaAlpha h1" data-property="font-size" data-unit="px">px

我现在需要做另一件事,它将从此HTML中获取选定的下拉值:

I now need to do another that will get the selected dropdown values from this HTML:

     <select class="selectChange" data-element=".homeTemplate #colaAlpha" data-property="height" data-unit="px">
         <option value="8">8px</option>
         <option value="12">12px</option>
         <option value="21">21px</option>
     </select>px

我想知道我应该怎么做?也许会发生一个财产变更事件吗?

I was wondering how I should go about doing this? is there perhaps a propertychange event that will work?

推荐答案

看看 http://api.jquery.com/更改/:

$(".selectChange").change(function (){
    alert($(this).val());
});

这篇关于用jQuery检测任何选定的下拉值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆