简体   繁体   English

如何在 IE9 中的不可见按钮上触发“点击”事件?

[英]How to trigger a “click” event on an invisible button in IE9?

Because of some very weird authorization problems, my CSS (or something) gets messed up and I can't see my button (<a..> anchor actually).由于一些非常奇怪的授权问题,我的 CSS(或其他东西)变得一团糟,我看不到我的按钮(实际上是 <a..> 锚点)。 I am using IE9 and don't have the option of using something else.我正在使用 IE9 并且没有使用其他东西的选项。 As far as I see JQuery 1.10.2 is loaded.据我所知,加载了 JQuery 1.10.2。

I'm not very interested in seeing my button, just in clicking on it, because I don't want to fix the CSS, I just want to access the backend (I'm not the frontend guy in this story).我对看到我的按钮不是很感兴趣,只是点击它,因为我不想修复 CSS,我只想访问后端(我不是这个故事中的前端人员)。

My button looks like this:我的按钮看起来像这样:

<a onclick="js.search()" href="javascript:void(0)" id="asdf12345">Search<img class="r" src="im/arrow-gray.gif"/></a>

What I've tried:我试过的:

  • First, I entered the id manually, within the IE9 Developer tools > HTML tab.首先,我在 IE9 开发人员工具 > HTML 选项卡中手动输入了 ID。 (the anchor had no id- that's why) (主播没有 id - 这就是为什么)
  • Tried to invoke the "js.search()" function manually, but js is not defined.尝试手动调用“js.search()”函数,但未定义js
  • I tried using the jQuery selector for the precise ID $('#asdf12345').trigger("click");我尝试使用 jQuery 选择器来获取精确的 ID $('#asdf12345').trigger("click"); but it also doesn't do anything.但它也没有做任何事情。

I'm not very experienced in the frontend, for instance I don't know why the "js" object isn't within scope in the console (cuz I can call the alert('asdf'); function for instance, so something does work).我在前端不是很有经验,例如我不知道为什么“js”对象不在控制台的范围内(因为我可以调用alert('asdf');函数,例如确实有效)。

So if anyone is aware of any way in which i can call my backend, simulating a click, that would help a lot!因此,如果有人知道我可以通过何种方式调用我的后端,模拟点击,那将大有帮助!

[EDIT] After failing to trigger the onClick programatically, taking Alex Shilman's suggestion, I messed around with the CSS - making my fonts smaller made it so that my images fit on the screen, so I could click on them. [编辑]在以编程方式触发onClick失败后,根据 Alex Shilman 的建议,我搞砸了 CSS - 使我的字体变小,以便我的图像适合屏幕,这样我就可以点击它们。

Take the inline onclick out and create an event handler with jquery like this:取出内联 onclick 并使用 jquery 创建一个事件处理程序,如下所示:

html: html:

<a id="asdf12345"> Search <img class="r" src="im/arrow-gray.gif"/></a>

JS: JS:

 $(function(){
  $('body').on('click', '#asdf12345', function(e){
    e.preventDefault();
    alert('clicked anchor');
  });
});

then you can do:那么你可以这样做:

$('#asdf12345').trigger("click");

If you're not seeing you image on the screen, try fiddling around with the css.如果您没有在屏幕上看到您的图像,请尝试摆弄 css。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM