我有一个函数可以通过 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 中获取选定的下拉列表值:
<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
我想知道我该怎么做?是否有一个 propertychange 事件可以工作?
最佳答案
看看http://api.jquery.com/change/ :
$(".selectChange").change(function (){
alert($(this).val());
});
关于jquery - 使用 jquery 检测任何选定的下拉值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12912513/