我正在使用下面的代码来更改<div>
. 它会更改字体大小,但首先您需要在下拉列表中选择大小,然后单击该文本,然后才会影响字体大小。但是,我希望立即更改所选文本的字体大小。你能帮助我吗?
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<form id="myform">
<select id="fs">
<option value="Arial">Arial</option>
<option value="Verdana">Verdana</option>
<option value="Impact">Impact</option>
<option value="Comic Sans MS">Comic Sans MS</option>
</select>
<select id="size">
<option value="7">7</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
</select>
</form>
<br/>
<div id="name" class="name">dsfdsfsfdsdfdsf</div>
<div id="address" class="address">sdfsdfdsfdsfdsf</div>
<div id="address1" class="address1">sdfsdfdsfdsfdsf</div>
脚本
$(".name").click(function(){
var id = this.id;
$("#"+id).css('font-size', $('#size').val()+"px");
});
$(".name").click(function(){
var id = this.id;//get clicked id
$("#"+id).css('font-family', $('#fs').val());
});