Javascript 从控制台和通过contentscript执行相同代码时的输出差异

Javascript 从控制台和通过contentscript执行相同代码时的输出差异,javascript,jquery,onclick,click,content-script,Javascript,Jquery,Onclick,Click,Content Script,我试图通过内容脚本人工触发点击。当从控制台尝试时,相同的代码可以工作并触发单击,但从contentscript尝试时不会 如果我尝试回显我正在应用单击的选定元素,我会得到以下结果:- 通过控制台 [<a class=​"blue apply-coupon">​APPLY COUPON​</a>​] 我尝试通过这两种方式触发单击。单击()并通过使单击均匀并触发:- 1. $('.coupon-section').find('a').click(); 2. var e =

我试图通过内容脚本人工触发点击。当从控制台尝试时,相同的代码可以工作并触发单击,但从contentscript尝试时不会

如果我尝试回显我正在应用单击的选定元素,我会得到以下结果:-

通过控制台

[<a class=​"blue apply-coupon">​APPLY COUPON​</a>​]
我尝试通过这两种方式触发单击。单击()并通过使单击均匀并触发:-

1. $('.coupon-section').find('a').click();

2. var e = jQuery.Event( "click" );
jQuery('.coupon-section a').trigger(e);
他们都不工作。有人能告诉我我做错了什么吗?当链接作为一个对象可用时,是否有任何方法可以触发,就像在contentscripts中一样

更新:在扩展链接对象时,我得到了这个。我只在单击之前添加对象

0: a.blue.apply-coupon
context: document
length: 1
prevObject: e.fn.e.init[1]
0: div.coupon-section
context: document
length: 1
prevObject: e.fn.e.init[1]
selector: ".coupon-section"
__proto__: Object[0]
_toggle: function (a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)}
add: function (a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))}
addClass: function (a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this}
after: function (){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}}
ajaxComplete: function (a){return this.on(b,a)}
ajaxError: function (a){return this.on(b,a)}
ajaxSend: function (a){return this.on(b,a)}
ajaxStart: function (a){return this.on(b,a)}
ajaxStop: function (a){return this.on(b,a)}
ajaxSuccess: function (a){return this.on(b,a)}
andSelf: function (){return this.add(this.prevObject)}
animate: function (a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cv(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cn.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=co.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)}
append: function (){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})}
appendTo: function (c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}
attr: function (a,b){return f.access(this,a,b,!0,f.attr)}
before: function (){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}}
bind: function (a,b,c){return this.on(a,null,b,c)}
blur: function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}
change: function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}
children: function (c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}
clearQueue: function (a){return this.queue(a||"fx",[])}
click: function (a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)}
0:a.blue.apply-优惠券
上下文:文档
长度:1
prevObject:e.fn.e.init[1]
0:分区优惠券部分
上下文:文档
长度:1
prevObject:e.fn.e.init[1]
选择器:“.优惠券部分”
__原型:对象[0]
_1.d=0,e=0,e=函数(c)c)c)c)c)c)c)var e数据(本次,“最后一次切换”数据(本次,“最后一次切换”数据(本次,“最后一次切换”数据(本次,“最后一次切换”数据(本次)b.b=b.b=b.b=参数,参数,参数,参数,c)b.a)函数(a)a)c,d.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.b.a.a.a.a.a a,a,P.电话(参数).join(“,”)}
clearQueue:函数(a){返回this.queue(a | |“fx”,[])}
单击:函数(a,c){c==null&&(c=a,a=null);返回参数.length>0?this.on(b,null,a,c):this.trigger(b)}
如果我问的问题不清楚,请发表评论


谢谢!

使用javascript暂时解决了此问题:-

document.getElementsByClassName('apply-coupon')[0].click();
仍然想知道为什么没有通过jQuery点击它

document.getElementsByClassName('apply-coupon')[0].click();