我有一个功能,通过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)
}
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<input class="inputChange" data-element=".homeTemplate #colaAlpha h1" data-property="font-size" data-unit="px">px
Run Code Online (Sandbox Code Playgroud)
我现在需要做另一个从这个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
Run Code Online (Sandbox Code Playgroud)
我想知道我应该怎么做呢?或许有一个可以运作的房地产交易活动?
Gee*_*ert 15
看看http://api.jquery.com/change/:
$(".selectChange").change(function (){
alert($(this).val());
});
Run Code Online (Sandbox Code Playgroud)