<select name=s1>
<option>Apple</option>
<option>Mango</option>
<option>Banana</option>
</select>
<select name=s2>
<option>text from s1</option>
</select>
我希望从s1中选择的文本将显示在s2上。我在jsp页面上编写此代码。请帮忙。
答案 0 :(得分:0)
HTML:-
<select name=s1 id='fruit' onchange='onFruitChange()'>
<option>Apple</option>
<option>Mango</option>
<option>Banana</option>
</select>
<select name=s2 id='getFruit'>
<option>text from s1</option>
</select>
jQuery:-
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript">
function onFruitChange(){
$('#getFruit').append( '<option value="'+$('#fruit').val()+'">'+$('#fruit').val()+'</option>' );
}
</script>
尝试一下!