如果你想的div自動顯示任何選擇框,您可以使用所選值以下的jQuery:
$('#first').change(function(){
/* target the first selectbox with id #first and bind a change event to it */
$('#firstvalue').html($(this).val());
/* set the html of the div with id #firstvalue to the selected option*/
});
/* the same for the second selectbox */
$('#second').change(function(){
$('#secondvalue').html($(this).val());
});
我會建議雖然改變你的HTML,使被處理的selectboxes具有相同並將其目標存儲在data
屬性中。像這樣:
HTML
<select class="show_val" data-target="#value_1">
<option>1</option>
<option>2</option>
</select>
<div id="value_1"></div>
jQuery的
$('.show_val').change(function(){
$($(this).data('target')).html($(this).val());
}
這樣,您就可以使用相同的jQuery的事件對所有selectboxes。
那麼,如果你只是*寫*給他/她...... ;-) – 2011-06-17 12:18:41
我想我是其中一個壞教師:(現在增加了一些解釋,所以它實際上教了一些東西 – Kokos 2011-06-17 12:19:13