是否使用jquery检测任何选定的下拉列表值?
我有一个功能,可以通过keyup检测所有输入值的变化: Jquery:是否使用jquery检测任何选定的下拉列表值?,jquery,Jquery,我有一个功能,可以通过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 inpu
// 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:
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
8px
12px
21px
二甲苯
我在想我该怎么做?可能有一个propertychange事件会起作用吗?看看:
与上面的复杂输入检测代码不同,这里的选择代码适用于我页面上的任何选择-它使用所选值和数据标记:
$('.selectChange').change(function() {
updateAllCSS($(this).attr('data-element'), $(this).attr('data-property'), $(this).val() + $(this).attr('data-unit'))
});
你已经试过什么了吗?嗨,谢谢你的回复,我能让这个应用于无限选择选项吗?
$(".selectChange").change(function (){
alert($(this).val());
});
$('.selectChange').change(function() {
updateAllCSS($(this).attr('data-element'), $(this).attr('data-property'), $(this).val() + $(this).attr('data-unit'))
});