开发者

how to disable textarea one line , not all line using javascript

i know <textarea name="textarea" disabled="disabled">dsds</textarea> can disable writ开发者_JS百科e in the textarea ,

but how to disable one line i want to disable in the textarea ?

not all line

thanks


That's not possible without JavaScript, even then:

  1. You need to enable contentEditable
  2. You need to write your own editor...
  3. You need to figure out what happens if someone deletes or inserts a line and therefore moves the disable one around
  4. You need to figure out what to do when someone hits enter in the line above the disabled one or backspace at the beginning of the line below the disabled one...

To sum it up, a textarea is the wrong approach here, better use multiple input's for whatever you want to do here, of course you will need to make it look like it's one textarea and you'll still need some JavaScript to make return work as expected (?), but then again you didn't specify what you want to do with this stuff.


Yes, use multiple input texts appear like a single text area, let's call it fake text area. That way disabling one would be easy.

  • Do not put any margin in between them and no border, all having same width.
  • Assign incremental ids to each one - like input-1,input-2 etc.
  • If you want to prefill some text into the fake textarea, calculate the maximum length that can be accomodated into a single input and fill line by line using javascript (jquery would be better).

  • When cursor is at the end of an input text and enter is pressed, take cursor to next text input. Define a function for every such possibility and call it.

  • On posting the form, append the input values together to get the actual value of the faked text area.

I guess there may be difficulties in faking a scrollbar for such a textarea but once implemented, should work fine. Any existing plugins like this?

Updates - For handling cursor positions, refer these things. I did not try myself but may be useful - Jquery Caret position and How to get cursor position in textarea and you can apply the cursor position getting-setting logics. Somehow try to get the actual click position and force the cursor to stay there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜