textarea

How to change color of selected text of textarea?

痞子三分冷 提交于 2019-12-06 10:33:01
I have textarea and i want to change color of selected text. Example: var text = "abcdefg"; I want to change color of selected text efg . here is my code: var input = document.getElementById('area'); var value = input.value.substr(input.selectionStart, input.selectionEnd - input.selectionStart); $('#abc').find(value).attr('color',color); Use ::selection CSS selector that select part of text is seleced. You can add your CSS property to selected text of elements. var textarea = document.querySelector("textarea"); textarea.selectionStart = 12; textarea.selectionEnd = 23; ::-moz-selection { color:

How to make a JTable column to contain not JTextFields, but JTextAreas?

被刻印的时光 ゝ 提交于 2019-12-06 09:49:13
问题 Please tell me, how to make a JTable column to contain JTextAreas, so the cell's height will increase when user types a lot of text and we can see more than one line (cell gets expanded; as result, row will expand too) 回答1: You need to write your own cell renderer and editor based on JTextArea: public class Start { public static class JTextPaneCellEditor extends AbstractCellEditor implements TableCellEditor, KeyListener { private JViewport viewport; private JTable table; private int row;

how to have undeletable words(part of text) in textarea

拥有回忆 提交于 2019-12-06 09:36:46
I am developing an application which needs a part of text in the textarea undeletable while they can add their text to the textarea . For example when user come to a web page it has a textarea which has a text {username} of that user. The user can add more text like {username} hi the the earth is globe but should be unable to delete {username} from that textarea. I am using Jquery as the javascript class, any idea that we can achieve it in Jquery? I think the only way to do this would be to perform a validation to make sure they didn't delete {username} , and display an error message (maybe

show html output in textarea instead of HTML code

蓝咒 提交于 2019-12-06 09:29:47
If I have a textarea including some HTML code, how can I write a JavaScript function to show the HTML output instead of HTML code itself, for example: <textarea id="mytextarea"> <table border=1><tr><td>cellone</td>td>celltwo</td></tr></table </textarea> <input type=button onclick="HTMLoutput();"/> <script> HTMLoutput() { //Code to show html output instead of html code in textarea } </script> How can I do this? What is the suggested code to write inside the HTMLoutput()? So to convert the the html code to a formated html you need to do: $('resultDiv').append($('<div/>').html($('.txtArea').val()

Replacing more than two line breaks with regex

丶灬走出姿态 提交于 2019-12-06 08:59:23
问题 I want to search my textarea for "\n" line breaks but I want two line spaces to be the maximum. What formula can I use in this regex so that it looks for anything over three \n 's in a row (" \n\n\n ") and replaces it with just one <br> ? this.replace(new RegExp('\n', 'gim') , '<br/>'); 回答1: this.replace(new RegExp('(\n){3,}', 'gim') , '<br/>'); This will replace 3 or more \n's with a br, make that 4 if you want 4 or more. 回答2: var newString = "some \n\n\n\n\n string".replace(/\n{3,}/g, '<br/

How to find whether text in a text area is wrapped to multiple lines?

早过忘川 提交于 2019-12-06 08:33:51
How can I find whether a long text in a textarea is wrapped into two or more lines? I'm not talking about the new line chars as discussed here . I'm aware of the plugin Textarea Line Count Any simpler method? I experimented on this and came up with a hack that involves the following: Disabling text-wrapping in the textarea (plus disable padding) Checking if the textarea's scrollWidth is greater than it's width . The basic logic i used was that if the text is spanning multiple lines, that means when wrapping is turned off, we should get a horizontal scrollbar. Demo : http://jsfiddle.net/fnG3d/

How do I add a default text to the beginning of an html text area?

浪子不回头ぞ 提交于 2019-12-06 08:05:40
问题 Im building a personal little social network. As part of the design, all statuses should begin with a default text that shouldn't change, similar to "Hi, my name is…" and then the user finishes the rest. Kind of like an HTML5 placeholder that doesn't go away. What would be the best way to accomplish this? 回答1: Note: For some dumb reason, I assumed jQuery (note that you do not need jQuery for this, but makes it a little easier). Here is one solution uses a combination of text-indent and an

textarea高度自适应解决方法

大憨熊 提交于 2019-12-06 07:45:06
引入autosize.js <script src="./autosize.js"></script> autosize(document.getElementsByTagName('textarea')); var textareas = document.getElementsByTagName('textarea'); for (var i =0;i<textareas.length;i++){ textareas[i].style.minHeight="60px"; } 下载地址 https://www.bootcdn.cn/autosize.js/ 来源: https://www.cnblogs.com/mlh1421/p/11968811.html

Disable / Enable button when the text and textarea are empty

谁说胖子不能爱 提交于 2019-12-06 07:16:50
问题 I have this code that disable the button when the text is empty, but I have a textarea html code. How can I include this that when the text and textarea are both empty the button will be disabled and when both are filled it enables. I tried the code below and it works on text only. Any ideas? $(document).ready(function() { $('input[type="submit"]').attr('disabled', true); $('input[type="text"]').on('keyup',function() { if($(this).val() != '') { $('input[type="submit"]').attr('disabled', false

jQuery Autosize plugin on dynamically added textarea elements

為{幸葍}努か 提交于 2019-12-06 06:45:14
Hi :) I'm using jQuery Autosize plugin to resize some of my textarea elements dynamically. Everything is good but the problem is that when I add some textarea elements to the DOM dynamically, the autosize thing no longer works. I initialize the plugin like so: $(document).ready(function () { $('textarea').autosize(); }); I tried to enable the plugin for my dynamically added textareas like: myDynamicallyAddedTextarea.autosize(); Unfortunately, nothing happened. Can anybody help me with this? sorry I can't comment yet, where are you adding this textarea at? can you post some of the code around