在图像上运行Javascript单击 [英] Run Javascript on Image Click

查看:50
本文介绍了在图像上运行Javascript单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有以下图形按钮:

I have the following graphical button on my site:

<a href="#" class="addto_cart_btn">
  <span id="btn_text">Click here to add to cart now</span>             
</a>

我想在点击时运行一个特定的javascript脚本(当前值#)来运行一些javascript - javascript代码本质上会生成一个包含其他内容的弹出式iFrame。

I want to run a specific javascript script when clicked (current value #) to run some javascript - the javascript code essentially generates a popup iFrame with additional content in it.

达到此目的的最佳方法是什么?

What is the best approach for achieving this?

推荐答案

试试这个

<script type="text/javascript">
   window.onload = function() {
      document.getElementById("btn_text").onclick = function() {
         // Do your stuff here
      };
   };
</script>

或者如果你可以使用JQuery

Or if you can use JQuery

<script type="text/javascript">
   $(document).ready(function() {
      $("#btn_text").click(function(){
         // Do your stuff here
      });
   });
</script>

这篇关于在图像上运行Javascript单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆