我的网站上有以下图形按钮:
<a href="#" class="addto_cart_btn">
<span id="btn_text">Click here to add to cart now</span>
</a>
我想在单击(当前值#)时运行特定的 javascript 脚本以运行一些 javascript - javascript 代码本质上会生成一个弹出式 iFrame,其中包含其他内容。
实现此目标的最佳方法是什么?
最佳答案
试试这个
<script type="text/javascript">
window.onload = function() {
document.getElementById("btn_text").onclick = function() {
// Do your stuff here
};
};
</script>
或者如果你可以使用 JQuery
<script type="text/javascript">
$(document).ready(function() {
$("#btn_text").click(function(){
// Do your stuff here
});
});
</script>
关于javascript - 在图像点击上运行 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19114183/