[英]How to Increase text size only?
我有一個代碼,我通過它增加文本區域中的文本的大小,我能夠通過給定的代碼執行此操作,但這是我的一個問題,當增加文本的大小時,它也增加了文本區域的大小和我不想要這個,也想讓文本區域可滾動
代碼如下:
<HTML>
<head>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(function () {
$('select[name="font"]').on('change', function () {
$('textarea').css('font-family', this.value);
});
});
</script>
</head>
<body>
Select Programming font:
<select name="font">
<option value="arial">arial black</option>
<option value="tahoma">tahoma</option>
<option value="times new roman">times new roman</option>
<option value="calibri">calibri</option>
</select>
<select onchange="$('#txt').css('font-size', event.target.value + 'px')">
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
</select>
<br>EnterValue:
<textarea id="txt" rows="4" cols="50">Test Test</textarea>
</body>
</html>
使用CSS為您的textarea提供特定尺寸。 然后,您可以將overflow屬性設置為auto,這將使瀏覽器自動呈現適當的滾動條:
#txt{
height:40px;
width:200px;
overflow:auto;
}
使用css resize:none;overflow:auto;width:100px;height:50px
with textarea
<textarea id="txt" rows="4" cols="50" style="resize:none;overflow:auto;width:300px;height:50px">Test Test</textarea>
演示: http : //jsfiddle.net/9BGT2/
<textarea id="txt" rows="4" cols="50" style="width:400px;height:100px">Test Test</textarea>
您可以在更改字體大小之前獲取textarea
的寬度和高度,然后將其設置回textarea
:
$(function () {
var width = $('textarea').width(),
height = $('textarea').height();
$('select[name="font"]').on('change', function () {
$('textarea').css('font-family', this.value);
$('textarea').width(width);
$('textarea').height(height);
}).change();
});
此解決方案不需要您為textarea
設置固定的寬度和高度
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.