textarea

How can I “undo” the programmatic insertion of text into a textarea?

房东的猫 提交于 2019-11-30 17:17:40
I have a textarea and a button. Clicking the button causes text to be inserted into the textarea. Is there a way to allow a user to press Ctrl/Cmd+z to undo the insertion of text and revert the textarea to its previous state? I think the easiest approach to leverage browser's undo stack instead of capturing events. To do this you need to use different codes for different browsers. Luckily out of all major browsers only Firefox has a different approach. // http://stackoverflow.com/a/9851769/529024 // Opera 8.0+ var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator

HTML textarea: use JavaScript to get wrapped text?

泄露秘密 提交于 2019-11-30 16:37:36
If I've got a textarea like this: <textarea id="foo" cols=80 wrap="hard"></textarea> Is there any way, using JavaScript, to grab the hard-wrapped text? I've tried the obvious $("#foo").val() , but that returns the unwrapped text. For example, if the textarea is: <textarea id="bar" cols=5 wrap="hard">a b c d e f</textarea> The browser will wrap the text to: a b c d e f And I was some way to grab that text – "a b c\nd e f" (which, because of wrap=hard , is the text that would be sent if the <textarea… was submitted in a <form… ). Since the formatting is done by the browser on submit, your best

how to block text selection without input textarea and select items

笑着哭i 提交于 2019-11-30 16:04:44
How to block text selection without input textarea and select items i actually have the script that works in IE but not in other browsers, here it is: var omitformtags=["input", "textarea", "select"] omitformtags=omitformtags.join("|") function disableselect(e){ if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1) return false } function reEnable(){ return true } if (typeof document.onselectstart!="undefined") document.onselectstart=new Function ("return false") else{ document.onmousedown=disableselect document.onmouseup=reEnable } document.onmousedown=click; function click() { if (

How to get the selected text from text area in react?

狂风中的少年 提交于 2019-11-30 15:54:55
问题 I am trying to make a text editor in react.Does anyone knows how to get the selected text from the textarea so that styles can be applied on the selected text.I know we can use window.getSelection in javascript but I am curious to know If any other methods are available for this functionality? 回答1: Yes there is a method to do this, specially in React. The way you should go to achieve this is as follow. step 1:- use ref in your textarea ui element. like `<textarea className='html-editor' ref=

How to get the selected text from text area in react?

此生再无相见时 提交于 2019-11-30 15:38:39
I am trying to make a text editor in react.Does anyone knows how to get the selected text from the textarea so that styles can be applied on the selected text.I know we can use window.getSelection in javascript but I am curious to know If any other methods are available for this functionality? Yes there is a method to do this, specially in React. The way you should go to achieve this is as follow. step 1:- use ref in your textarea ui element. like `<textarea className='html-editor' ref='myTextarea' value = {this.state.textareaVal} onChange={(event)=>{ this.setState({ textareaVal:event.target

enter does not work in textarea in Internet Explorer 8

删除回忆录丶 提交于 2019-11-30 14:33:08
When I press enter in a textarea which has whitespace attribute is set to nowrap through css, it is ineffective. No new line is created. Instread a simple whitespace appears. This is only true in IE8. I Have tried current version of Opera,Chrome and Firefox and I have not encountered such problems. Do you have some solution for this? Thanks.. I have this: .gwt-TextArea { white-space:nowrap; } where gwt-TextArea sets the textarea. Also, I have tried .gwt-TextArea { white-space:pre; } It seems to give the same result. This article says Internet Explorer ignores line breaks with white-space:

How can I set the value of a CodeMirror editor using Javascript?

放肆的年华 提交于 2019-11-30 13:08:43
问题 I try to set id4 in the following code: <div id="id1"> <div id="id2"> <div id="id3"> <textarea id="id4"></textarea> </div> </div> </div> By using this code: document.getElementById('id4').value = "..."; And this: document.getElementById('id3').getElementsByTagName('textarea')[0].value = "..."; But nothing works. UPDATED: The textarea is replaced by CodeMirror editor. How do I set value to it? Thanks a lot for the help! 回答1: The way to do this has changed slightly since the release of 3.0. It

Jquery help to enforce maxlength on textarea?

跟風遠走 提交于 2019-11-30 12:46:22
Here is Jquery to enforce maxlength for textarea when you add the attribute "maxlength". Maxlength is not supported with IE. How do I adjust my code to handle multiple textarea(s) on the page? Currently if I add text to any textarea, they all countdown with the same value. Jquery: $(document).ready( function () { maxLength = $("textarea").attr("maxlength"); $("textarea").after("<div><span id='remainingLengthTempId'>" + maxLength + "</span> remaining</div>"); $("textarea").bind("keyup change", function(){checkMaxLength(this.id, maxLength); } ) }); function checkMaxLength(textareaID, maxLength){

How to set the initial text in a TinyMCE textarea?

て烟熏妆下的殇ゞ 提交于 2019-11-30 12:36:27
I'm in a curious situation where I previously had no problem achieving what I'm looking for. The following code is a part of an HTML page which is to host a TinyMCE rich textbox: ... <textarea id="editing_field">This text is supposed to appear in the rich textbox</textarea> ... At first this worked as intended, creating a rich textbox with the enclosed text in it. At some point, though, the TinyMCE code decided that the textarea HTML should be transformed to the following: <textarea id="editing_field" style="display: none;"/> This text is supposed to appear in the rich textbox This renders the

Disable linebreaks in HTML textarea

a 夏天 提交于 2019-11-30 12:10:18
with CSS or any other way, is it possible to disallow newlines in a HTML textarea? So basically I want nothing to happen when the user presses "enter". Using jQuery, you could do it like this: $(document).ready(function() { $("#t_area").keypress(function(event) { if(event.which == '13') { return false; } }); }); <textarea id="t_area"></textarea> I would also strip out any newlines using PHP or ASP or whatever server-side scripting language you have access to as well to be completely thorough. its posible with wrap="soft,hard, or off 来源: https://stackoverflow.com/questions/4651755/disable