开发者

Greasemonkey (JavaScript) textarea question

I have written a basi开发者_开发技巧c Greasemonkey script which passes an output out to a textarea, like this:

var obj = document.getElementById("comment").innerHTML = "\n" + "Note:" + "\n" + "\n" + output_string;

It works like a charm, if you change the value from the source, it will update the textarea. However, as soon as you write anything yourself inside the textarea and select a value, it will not overwrite what you written inside the textarea. And you need to refresh the page entirely to be able to use the function again. Why is that?


The textarea's value attribute is set as soon as you type something into it. This overrides any innerHTML value.

You should be using the value attribute to set the contents of input elements like textarea.

Try this instead:

var obj = document.getElementById("comment").value = "\n" + "Note:" + "\n" + "\n" + output_string;


If you need your text area to always display the same text I suggest you attach blur event on it using your customized greasemonkey script. Blur event would do the same thing as it does now. The only change would be that textarea will be updated the moment cursor focuses off the textarea.

If that's what you were after, 'cause I didn't understand it quite clearly what are you trying to do.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜