textarea

Display current line and column number for a textarea

。_饼干妹妹 提交于 2019-12-22 06:57:02
问题 I'm making a file edit interface in my web-app, I have a textarea with file contents. When textarea is focused, I want to output the position of the cursor, i.e. line number and column: this is useful because error messages usually yield a line number, for example. The question is: how do I figure out the position of the cursor in textarea? I'm using prototype library. Maybe there's a solution already? I'm not really interested in fancy toolbars for the textarea, which are offered by those

How to simulate Chrome/Safari border around active input or textarea on other elements such as divs or iframes?

房东的猫 提交于 2019-12-22 05:37:16
问题 I was using simple textarea element and then replaced it with iframe with designMode='on' to give user the possibility to mark some text and make it italic. But I still want an iframe to look like textarea, so I need a border around it similar to that which appears in Chrome and Safari when textarea is active. How can I achieve such an effect? 回答1: You can get the rounded outline in webkit like this: outline: 2px auto red; Notice that the width of the outline will not obey the specified width

How to add resizer to textarea in IE?

给你一囗甜甜゛ 提交于 2019-12-22 05:28:18
问题 How to add resizer to textarea in IE the same as in Chrome and Firefox? jQuery.resizable() won't work for me. 回答1: Internet Explorer (and Microsoft Edge, as of May 5, 2016) do not support native gripper/resizing on textarea elements. While these may eventually be supported in the future (in Microsoft Edge), the best option you have for now is to polyfill the functionality. Many options exist online that do this, but if you're using jQuery and jQuery UI, you could use the Resizable widget: $(

jQuery Escaping HTML from a Textarea

我们两清 提交于 2019-12-22 04:46:12
问题 I want to escape HTML tags to entity names, taking text from a textarea and putting the result in a second textarea such that: <mytag> becomes <mytag> I'm using .html() and .text() going back and forth OK. My problem is dealing with the textarea element, which acts a little different. It works fine if I first place the text into a div: var htmlStr = $('#textareaInput').val(); //doesn't like .html() .text() ? $('#dummy').text(htmlStr); // an object to hold the text that supports .html() $('

Adding disable/enable methods to Summernote editor

蓝咒 提交于 2019-12-22 04:32:35
问题 I have been using summernote editor for a while now and it's working for most of the things I've needed it for. However, I recently wanted it disabled ( not destroyed ) after a user action. After efforts without success, it occurred to me I could use the destroy() method to achieve what I wanted. I noticed that Summernote still turned an already disabled textarea to its editor, with the writing area disabled. Here is what I finally did: To disable summernote after creating it: I first

Is it possible to disable textarea's multiline option?

雨燕双飞 提交于 2019-12-22 01:52:25
问题 Of course, I can use standard html text box, but I need text area for some reason. So, is it possible to disable textarea's multiline option? 回答1: You can set the size of your textarea using the cols and rows attributes and make it non-resizable in CSS but you can't prevent the user from adding more than one line. Even if the area is just too small, a scrollbar will appear and let them write as many lines as they want. If you really need to get just one line, I suggest setting the rows

How to count words in a textarea by jquery and return that value

喜夏-厌秋 提交于 2019-12-22 01:05:08
问题 function count(){ var val = $.trim($('textarea').val()), words = val.replace(/\s+/gi, ' ').split(' ').length, chars = val.length; if(!chars)words=0; return words; } This function always return 0? Please help. 回答1: You can split the textarea value on spaces and then get the words length in it. Try this: var words = $('textarea').val().split(' '); alert(words.length);//or return words.length; working Demo 回答2: text_area = $('textarea').val(); text_area.length == 0 ? 0 : text_area.trim().split(/

How to change color of text in a textarea

和自甴很熟 提交于 2019-12-21 23:16:06
问题 I have a textarea and when I type something, for some words the color should change. For example, if the typed text is next one: He went to the market to buy an apple The "market" word should become green The "apple" word should become red This is my current code: var str = 'market'; var value = str.includes('market'); if (value == str) { document.getElementById("text").style.color = "green"; } else { document.getElementById("text").style.color = "red"; } <textarea rows="9" cols="100" id=

setSelectionRange not behaving the same way across browsers?

故事扮演 提交于 2019-12-21 20:22:38
问题 I found this on a different question: setCaretToPos = function(input, selectionStart, selectionEnd){ if(input.setSelectionRange){ input.focus(); input.setSelectionRange(selectionStart, selectionEnd); }else if(input.createTextRange){ var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } }; setCaretToPos(8, 12); It should select text from a text area between the 8th character and 12th

TrimPath - Js模板引擎

霸气de小男生 提交于 2019-12-21 14:15:40
  当页面中引用template.js文件之后,脚本将创建一个TrimPath对象供你使用。 parseDOMTemplate(elementId,optionalDocument)  //获得模板字符串代码   得到页面中Id为elementId的DOM组件的InnerHTML,将其解析成一个模板,这个返回一个templateObject对象,解析出错时将抛出一个异常。   optionalDocument一个可选参数,在使用iframe,frameset或者默认多文档时会有用,通常用来做模板的DOM元素师一个隐藏的<textarea>。   以上方法的到的模板(字符串)再经过process()方法进一步解析就得到了最终的源代码。   如: var result = parseDOMTemplate(elementId,optionalDocument).process();  //用数据替换模板   这个方法也直接能用于解析字符串: var data = { Name:"张辽" };       //不输入就包ul,输入就包你输入的那个 var result = TrimPath.processDOMTemplate("temp", data); document.getElementById("ShowDiv").innerHTML = result; alert(