点击事件上的jQuery未定义变量

时间:2015-01-11 12:07:18

标签: javascript jquery html

我在网站上有多个按钮,我无法将数据属性写入变量。

我的HTML

<button id="verzije" data-href="http://example.com/qjzvq6pxk1ru" data-sub="http://example.com/podnapisi/file.txt" data-vers="1">1. verzija</button> 
<button id="verzije" data-href="http://example.com/f/4pXOzy" data-sub="http://example.com/podnapisi/file.txt" data-vers="2">2. verzija</button> 
<button id="verzije" data-href="http://example.com/eo0hn7ajh4j3" data-sub="http://example.com/podnapisi/file.txt" data-vers="3">3. verzija</button>

我的javascript

jQuery(document).ready(function(){
    jQuery("button").click(function(e){
        e.preventDefault();
        var film = jQuery(this).data('href');
        var pod = jQuery(this).data('sub');
        var capback = jQuery(this).data('cap');
        var verz = jQuery(this).data('vers');
        jQuery.post("http://example.com/filmi.php",
        {
          link: film,
          sub: pod,
          cap: capback,
          vers: verz
        },
        function(data){
          jQuery('#flashplayer').html(data);
        });
    });
});

此代码工作了一段时间,然后我在我的网站上添加了广告,代码停止了工作。这段代码还有其他方法吗?我试图取消绑定广告的事件听众,但它没有工作。如果我打开我的adblock,一切都很完美,如果它关闭它就不起作用。有解决方案吗

注意:我包含了jQuery!

1 个答案:

答案 0 :(得分:0)

您所拥有的代码应该可行,但有一些报告称可能的JS与Google广告冲突。请参阅herehere。在链接到的情况下,window.onload vs (document).ready事件被两个函数重新绑定。 第二个链接说明了你可能的答案:

$(function() {

而不是

jQuery(document).ready(function() {

您也应该更改id

相关问题