简体   繁体   中英

JQuery/Firefox bug with textarea and .text?

Code can be tested here: http://jsfiddle.net/yWUTK/3/

<textarea id='textbox'></textarea>

<span onclick="$('#textbox').text('One');">One</span>
<span onclick="$('#textbox').text('Two');">Two</span>

Behaviour for this in Chrome and Firefox is the same, you click One or Two and it changes the textarea. However, on firefox, if you then manually change the content of the textarea, it no longer updates when you click. Chrome continues to work fine.

I'm running firefox 3.6.15

Can anyone explain this behaviour? I'm not sure if I am doing something wrong, or if it's a genuine bug. My actual implementation uses proper markup and $(document).ready etc.

You are indeed correct, however, changing them to val() works .

<span onclick="$('#textbox').val('One');">One</span>
<span onclick="$('#textbox').val('Two');">Two</span>

val() is arguably the more correct method to use as well.

Also, I'm sure you are aware, you shouldn't use inline event handlers except in trivial examples like above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM