Javascript greasemonkey中的Var无法传递到属性

Javascript greasemonkey中的Var无法传递到属性,javascript,greasemonkey,Javascript,Greasemonkey,大家好,我不是Javascript和gresemonkey中的noobie方面的专家,我需要你们的帮助。 下面是代码: // ==UserScript== // @name Button RT // @include *rt* // @version 1 // ==/UserScript== // create button var anid= document.getElementsByClassName( 'value id' )[ 0 ].innerHTML;

大家好,我不是Javascript和gresemonkey中的noobie方面的专家,我需要你们的帮助。 下面是代码:

// ==UserScript==
// @name        Button RT
// @include     *rt*
// @version     1
// ==/UserScript==
// create button
var anid= document.getElementsByClassName( 'value id' )[ 0 ].innerHTML;
var btn = document.createElement( 'input' );
with( btn ) {
  setAttribute( 'onclick', 'window.open(http://www.google.com"+ anid)    ');
  setAttribute( 'value', 'Button!' );
  setAttribute( 'type', 'button' );
}
// append at end
document.getElementsByClassName( 'value id' )[ 0 ].parentNode.appendChild( btn );
那么我做错了什么?因为anid变量在onclick事件中显示为anid,而不是它应该显示的。我错过了什么? 我从萤火虫那里得到了类似的东西

<input type="button" onclick="window.open("http://www.google.com"+ ticketid) " value="Button!!">

setAttribute onclick,window.open'http://www.google.com“+anid+

它也不起作用。我不得不把它改成“窗口”。openhttp://www.google.com“+anid+”,现在它可以工作了,看到了吗?现在我们都在同一件事上搞砸了。避免此类错误的一个好方法是:var server=;var myUrl=anid;var completeUrl=server+myUrl;嘿,是的。我甚至试过,但由于某些原因,它不起作用:/