onClick,输入类型=" image" [英] onClick with input type="image"

查看:62
本文介绍了onClick,输入类型=" image"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个确定的答案。基本上,我想将Google Analytics事件跟踪添加到表单提交 - 我希望添加一个onClick,但我很难找到所有浏览器是否支持它。

I have been going round and round trying to find a definitive answer. Basically, I want to add the Google Analytics event tracking to a form submit - I was hoping to add an onClick to it, but I am having a tough time finding out if all the browsers support it.

我问设计表单的人,她说他们没有使用按钮类型的原因是导致在某些浏览器中提交表单的问题,但是不记得是哪一个。

I asked the person who designed the form, and she said that the reason they didn't use the button type is that is caused issues submitting the form in some browsers, but could not remember which ones.

那么,它会在浏览器中运行,还是应该切换到按钮?

So, will it work across browsers, or should I switch to button?

以下相关代码:

<input name="submit" id="submitme" type="image" 
  src="/graphics/creative/landing_pages/popup/ibd_signmeupbtn.gif" 
  alt="Sign Me Up!" 
  onClick="_gaq.push(['_trackEvent', 'Registrations', 'Register', 'Lightbox']);"
  tabindex="8"  />

编辑我已定义了_gaq。这个问题的真正目标是确保使用带有输入图像的onClick即可。

EDIT I have _gaq defined. The real goal of this question is to make sure that using an onClick with an input image is OK to do.

推荐答案

尝试接线它有点不同

<input name="submit" id="submitme" type="image" 
    src="/graphics/creative/landing_pages/popup/ibd_signmeupbtn.gif" 
    alt="Sign Me Up!" 
    onclick="SignMeUp();"
    tabindex="8"  />

并像这样创建你的函数:

And create your function like so:

<script type="text/javascript">
    function SignMeUp()
    {
        if (!!_gaq) // make sure _gaq is defined
            _gaq.push(['_trackEvent', 'Registrations', 'Register', 'Lightbox']);
    }
</script>

这篇关于onClick,输入类型=&quot; image&quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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