I have the following code which works to a degree with text开发者_开发技巧 fields but not textareas
javascript:(function(){for(var%20text=prompt('enter%20text%20to%20fill')||'',ins=document.getElementsByTagName('input'),it,m=ins.length,i=0;i<m;i++){it=ins[i];if(it.name=='text')it.value=text;};}());
Thanks for any help.
A simplified example, based on your bookmarklet:
Readable version:
(function(){
var t = prompt('enter text to fill') || '',
ta = document.getElementsByTagName('textarea'), n = ta.length;
while(n--){
ta[n].value = t;
}
}());
Bookmarklet:
javascript:(function(){var%20t=prompt('enter%20text%20to%20fill')||'',ta=document.getElementsByTagName('textarea'),n=ta.length;while(n--){ta[n].value=t;}}());
Change:
ins=document.getElementsByTagName('input')
to
ins=document.getElementsByTagName('textarea')
and remove
if(it.name=='text')
Note: this will insert your text into all textareas in the document
精彩评论