开发者

jQuery val('') does not clears new lines?

开发者 https://www.devze.com 2023-02-04 09:48 出处:网络
Or i\'m doing something wrong? $(\'textarea\').val(\'\') keeps new li开发者_如何学编程ne in textarea if there were any of them.

Or i'm doing something wrong?

$('textarea').val('') 

keeps new li开发者_如何学编程ne in textarea if there were any of them.

Any solution?


Hmm jQuery 1.4.4 does not do it like you say either in Chrome, FF3.6 or IE8, here is a demo :

http://jsfiddle.net/subtenante/abk3V/

Add new line characters in the textareas, click on "empty!" and all the characters disappear.


I have spotted this issue second time in another project and decided to figure out what is happening. Started to dig and figured out it was \n in textarea.

Started to watch the process of textarea usage and found that there were mistake in the code inside handler for keydown of textarea.

I forgot to return false at the end. That's why key "enter" were adding additional \n in the textarea. :D

Maybe that helps anyone.

Sorry everyone. Topic is closed :)

0

精彩评论

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