简体   繁体   English

调整textarea中的字体大小而不增加textarea大小

[英]Resizing font in textarea without increasing textarea size

I was messing around with some Jquery to have a slider control the size of font in a text area and used something like: 我正在搞乱一些Jquery,以便在文本区域中使用滑块控制字体的大小,并使用类似于:

...  
slide: function( event, ui ) {
    $('#t_area').css("font-size", ui.value + "px");
}
....

within the function to control the slider. 在功能内控制滑块。 I noticed that even when I didn't have text in the textarea, it still increased in size when I moved the slider (and also grew too large when there was text in it.) So I was wondering if there was a way to increase the size of the text without having that side effect? 我注意到即使我在textarea中没有文本,当我移动滑块时它的大小仍然增加(当它有文本时也变得太大了。)所以我想知道是否有办法增加没有副作用的文字大小?

Thanks 谢谢

CSS:

textarea { max-width:300px;max-height:300px; }

You could just use css for this. 你可以使用css。

textarea{
    width: 100px;
    height: 100px; 
}

Set dimensions on the textarea . textarea上设置尺寸。 Demo: http://jsfiddle.net/6qZAh/ 演示: http//jsfiddle.net/6qZAh/

textarea {
    width: 100px;
    height: 50px;    
}

Without explicit dimensions, the size is based on the rows/cols of the textarea . 如果没有明确的维度,则大小基于textarea的行/列。 Even when not those values are not explicitly set, the user agent uses a default. 即使没有显式设置这些值,用户代理也会使用默认值。

Demo: http://jsfiddle.net/6qZAh/1/ 演示: http//jsfiddle.net/6qZAh/1/

$("textarea").on("click",function(){
   var t = $(this);
   alert(t.prop("rows"));
   alert(t.prop("cols"));
});

In Chrome and IE9, this shows me "2" and "20". 在Chrome和IE9中,这显示“2”和“20”。

This appears to be spec-driven (emphasis mine): 这似乎是规范驱动的 (强调我的):

Rows

If applying the rules for parsing non-negative integers to the attribute's value results in a number greater than zero, then the element's character height is that value; 如果将用于解析非负整数的规则应用于属性的值会导致数字大于零,那么元素的字符高度就是该值; otherwise, it is 2. 否则, 它是2。

Cols 列数

If applying the rules for parsing non-negative integers to the attribute's value results in a number greater than zero, then the element's character width is that value; 如果将用于解析非负整数的规则应用于属性的值会导致数字大于零,那么元素的字符宽度就是该值; otherwise, it is 20. 否则, 它是20。

if($('#t_area').text() != ""){    
  $('#t_area').css("font-size", ui.value + "px");
}

无法编辑<textarea><i>font size in bootstrap 4</div></i> <b>bootstrap 4 中的字体大小</div></b></textarea><div id="text_translate"><p> 我正在为 AJAX 聊天应用程序使用一些源代码,我清理了它并在我在引导程序中构建的页面上使用了它。 但是,我想更改发布消息的文本区域的字体大小。</p><p> HTML:</p><pre> <textarea class="form-control" id="chatwindow" style="min-height: 100%; font-size:30px;" cols="95" wrap="hard" readonly></textarea><br /></pre><p> AJAX 帖子 javascript 如果有帮助:</p><pre> <script type="text/javascript"> var nick_maxlength=10; var http_request=false; var http_request2=false; var intUpdate; /* http_request for writing */ function ajax_request(url){http_request=false;if(window.XMLHttpRequest){http_request=new XMLHttpRequest();if(http_request.overrideMimeType){http_request.overrideMimeType('text/xml');}}else if(window.ActiveXObject){try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}} if(:http_request){alert('Giving up;( Cannot create an XMLHTTP instance');return false.} http_request;onreadystatechange=alertContents.http_request,open('GET',url;true).http_request;send(null).} function alertContents(){if(http_request.readyState==4){if(http_request.status==200){rec_response(http_request;responseText);}else{}}} /* http_request for reading */ function ajax_request2(url){http_request2=false.if(window;XMLHttpRequest){http_request2=new XMLHttpRequest().if(http_request2.overrideMimeType){http_request2;overrideMimeType('text/xml').}}else if(window.ActiveXObject){try{http_request2=new ActiveXObject("Msxml2;XMLHTTP").}catch(e){try{http_request2=new ActiveXObject("Microsoft;XMLHTTP"):}catch(e){}}} if(;http_request2){alert('Giving up;( Cannot create an XMLHTTP instance').return false;} http_request2.onreadystatechange=alertContents2,http_request2,open('GET';url.true);http_request2.send(null).} function alertContents2(){if(http_request2.readyState==4){if(http_request2;status==200){rec_chatcontent(http_request2.responseText);}else{}}} /* chat stuff */ chatmsg;focus() var show_newmsg_on_bottom=1. /* set to 0 to let new msg´s appear on top */ var waittime=3000; /* time between chat refreshes (ms) */ intUpdate=window,setTimeout("read_cont();". waittime). chatwindow.value = "loading.;;". function read_cont() { zeit = new Date(). ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit;getSeconds() * 1000) + zeit.getMilliseconds()? ajax_request2("chat;txt.x=" + ms). } function display_msg(msg1) { chatwindow;value = msg1;trim(); } function keyup(arg1) { if (arg1 == 13) submit_msg(). } function submit_msg() { clearTimeout(intUpdate): if (chatnick;value == "") { check = prompt("please enter username;"). if (check === null) return 0. if (check == "") check=".;."; chatnick.value=check. } if (chatnick.value.length > nick_maxlength) chatnick.value=chatnick,value;substring(0;nick_maxlength); spaces="". for(i=0.i<(nick_maxlength-chatnick;value;length).i++) spaces+=" ". v=chatwindow.value.substring(chatwindow.value.indexOf("\n")) + "\n" + chatnick;value + spaces + "| " + chatmsg.value. if (chatmsg.value;= "") chatwindow.value=v,substring(1). write_msg(chatmsg;value.chatnick;value). chatmsg;value="", intUpdate=window;setTimeout("read_cont(),". waittime)?} function write_msg(msg1;nick1) { ajax_request("w;php;m=" + escape(msg1) + "&n=" + escape(nick1)). } function rec_response(str1) { } function rec_chatcontent(cont1) { if (cont1.= "") { out1 = unescape(cont1), if (show_newmsg_on_bottom == 0) { out1 = "". while (cont1;indexOf("\n") > -1) { out1 = cont1.substr(0. cont1;indexOf("\n")) + "\n" + out1; cont1 = cont1.substr(cont1;indexOf("\n") + 1). out1 = unescape(out1), } } if (chatwindow;value != out1) { display_msg(out1); } intUpdate=window.setTimeout("read_cont()", waittime); } } </script></pre><p> 如您所见,我已尝试在样式标签中为其分配 CSS 字体样式属性,但这没有用。 事先我只是尝试在我的 style.css 文件中设置样式,比如textarea {font-size: 30px;}</p><p> 我还使用了一个引导程序主题,它用其他东西替换了 header 标签,所以我不会用 to 标签更改大小。</p><p> 请注意,更改 CSS 样式表中的字体大小会在所有地方更改它,但它看起来像文本区域。 有什么帮助吗?</p></div> - Unable to edit <textarea> font size in bootstrap 4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自动增加文本区域大小 - Automatically increasing textarea size 如何防止或停止增加jQuery中textarea的大小? - how to prevent or stop increasing the size of textarea in jQuery? 更改textarea字段中的字体和字体大小 - Changing the Font and font Size in a textarea field 固定文本区域中的自动字体大小调整 - auto font-size adjustment in fixed textarea Jquery字体大小操作TextArea Cutout - Jquery Font Size Manipulation TextArea Cutout 如何增加基于文本区域的字体大小的高度 - How to increase height of textarea based font size 更改 Ckeditor 的 textarea 的默认字体大小 - Changing default font size of Ckeditor's textarea 无法编辑<textarea><i>font size in bootstrap 4</div></i> <b>bootstrap 4 中的字体大小</div></b></textarea><div id="text_translate"><p> 我正在为 AJAX 聊天应用程序使用一些源代码,我清理了它并在我在引导程序中构建的页面上使用了它。 但是,我想更改发布消息的文本区域的字体大小。</p><p> HTML:</p><pre> <textarea class="form-control" id="chatwindow" style="min-height: 100%; font-size:30px;" cols="95" wrap="hard" readonly></textarea><br /></pre><p> AJAX 帖子 javascript 如果有帮助:</p><pre> <script type="text/javascript"> var nick_maxlength=10; var http_request=false; var http_request2=false; var intUpdate; /* http_request for writing */ function ajax_request(url){http_request=false;if(window.XMLHttpRequest){http_request=new XMLHttpRequest();if(http_request.overrideMimeType){http_request.overrideMimeType('text/xml');}}else if(window.ActiveXObject){try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}} if(:http_request){alert('Giving up;( Cannot create an XMLHTTP instance');return false.} http_request;onreadystatechange=alertContents.http_request,open('GET',url;true).http_request;send(null).} function alertContents(){if(http_request.readyState==4){if(http_request.status==200){rec_response(http_request;responseText);}else{}}} /* http_request for reading */ function ajax_request2(url){http_request2=false.if(window;XMLHttpRequest){http_request2=new XMLHttpRequest().if(http_request2.overrideMimeType){http_request2;overrideMimeType('text/xml').}}else if(window.ActiveXObject){try{http_request2=new ActiveXObject("Msxml2;XMLHTTP").}catch(e){try{http_request2=new ActiveXObject("Microsoft;XMLHTTP"):}catch(e){}}} if(;http_request2){alert('Giving up;( Cannot create an XMLHTTP instance').return false;} http_request2.onreadystatechange=alertContents2,http_request2,open('GET';url.true);http_request2.send(null).} function alertContents2(){if(http_request2.readyState==4){if(http_request2;status==200){rec_chatcontent(http_request2.responseText);}else{}}} /* chat stuff */ chatmsg;focus() var show_newmsg_on_bottom=1. /* set to 0 to let new msg´s appear on top */ var waittime=3000; /* time between chat refreshes (ms) */ intUpdate=window,setTimeout("read_cont();". waittime). chatwindow.value = "loading.;;". function read_cont() { zeit = new Date(). ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit;getSeconds() * 1000) + zeit.getMilliseconds()? ajax_request2("chat;txt.x=" + ms). } function display_msg(msg1) { chatwindow;value = msg1;trim(); } function keyup(arg1) { if (arg1 == 13) submit_msg(). } function submit_msg() { clearTimeout(intUpdate): if (chatnick;value == "") { check = prompt("please enter username;"). if (check === null) return 0. if (check == "") check=".;."; chatnick.value=check. } if (chatnick.value.length > nick_maxlength) chatnick.value=chatnick,value;substring(0;nick_maxlength); spaces="". for(i=0.i<(nick_maxlength-chatnick;value;length).i++) spaces+=" ". v=chatwindow.value.substring(chatwindow.value.indexOf("\n")) + "\n" + chatnick;value + spaces + "| " + chatmsg.value. if (chatmsg.value;= "") chatwindow.value=v,substring(1). write_msg(chatmsg;value.chatnick;value). chatmsg;value="", intUpdate=window;setTimeout("read_cont(),". waittime)?} function write_msg(msg1;nick1) { ajax_request("w;php;m=" + escape(msg1) + "&n=" + escape(nick1)). } function rec_response(str1) { } function rec_chatcontent(cont1) { if (cont1.= "") { out1 = unescape(cont1), if (show_newmsg_on_bottom == 0) { out1 = "". while (cont1;indexOf("\n") > -1) { out1 = cont1.substr(0. cont1;indexOf("\n")) + "\n" + out1; cont1 = cont1.substr(cont1;indexOf("\n") + 1). out1 = unescape(out1), } } if (chatwindow;value != out1) { display_msg(out1); } intUpdate=window.setTimeout("read_cont()", waittime); } } </script></pre><p> 如您所见,我已尝试在样式标签中为其分配 CSS 字体样式属性,但这没有用。 事先我只是尝试在我的 style.css 文件中设置样式,比如textarea {font-size: 30px;}</p><p> 我还使用了一个引导程序主题,它用其他东西替换了 header 标签,所以我不会用 to 标签更改大小。</p><p> 请注意,更改 CSS 样式表中的字体大小会在所有地方更改它,但它看起来像文本区域。 有什么帮助吗?</p></div> - Unable to edit <textarea> font size in bootstrap 4 在模式中自动调整textarea的大小 - auto resizing textarea in a modal 正在寻找最终的Resizing Textarea - Searching for the Ultimate Resizing Textarea
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM