每次选择下拉颜色时,我都希望使用document.write()打印变量'value'。
<script type="text/javascript">
var value = 'xyz';
$(document).ready(function(){
$('#button1').click(function(){
value = $('#combo').val();
alert (value);
});
});
</script>
<select id = "combo">
<option>White</option>
<option>Yellow</option>
<option>Fuchisa</option>
<option>Red</option>
<option>Silver</option>
<option>Gray</option>
<option>Olive</option>
</select>
<input id="button1" type="button" value="Click!" />
<p><script type="text/javascript"> document.write(value) </script></p>
答案 0 :(得分:3)
$('#button1').click(function() {
value = $('#combo').val();
$('p').html(value);
});