IE11 + jQuery 1.8.3: dynamically added textarea wi

2019-07-07 02:03发布

问题:

This is very likely a bug, but I'm reporting it here for reference and for the slight chance of someone being able to propose a workaround.

IE 11 supports the placeholder attribute natively on textarea elements. That's great. But adding a new textarea with a placeholder to the DOM, it automatically puts the placeholder text into the textarea's field, too!

Here's the repro: http://jsfiddle.net/wE577/1/

回答1:

Fiddling around on jsfiddle, it turns out that from jQuery 1.9 onwards, this problem does not occur: http://jsfiddle.net/wE577/2/.

A weird problem indeed. Unfortunately, my google foo didn't turn up any bug reports on this.

Since at the moment, we cannot upgrade jQuery beyond 1.8.3 (although I hope we soon will), a workaround I came up with is setting the placeholder attribute after adding the new textarea element to the DOM, which works flawlessly.



回答2:

We are using jquery version 1.10.1 but still facing the issue,

<textarea placeholder='Max 250 characters'>Max 250 characters</textarea>

For this we emptied the value of textarea while clicking (or calling), like this

$('#textareaID textarea').val('');