duanrang2627 2015-01-21 11:08
浏览 96
已采纳

根据PHP条件启用jquery click事件

I'm trying to edit a wordpress template for a multi-video page. Each video item can be clicked to play the video, however I want that click event enabled ONLY if a link is defined (in the wordpress shortcodes). You can see an example of the video page here: http://madbunny.us/vixen/demo/all/dark/multi-video/

This is for a portfolio website, so having the image still as an item, but without a video is very important for me, if there is no link.

UPDATE: After I tweaked it based on Jay Hewitt's reply, it does what I want, but it introduced a new problem, it can go to the next video, but won't go back to the previous video that doesn't have a url (click event disabled).

jQuery('.multivideo-center-play-btn, .multivideo-preview').each(function(){
    var _self = jQuery(this);
    _self.bind('click',function(){
        if(_self.parent().find(".hidden-url").text() != ""){
            var $vid = jQuery(this).parent();
            if ($vid.hasClass('active') || isAMobile)playVideo($vid);
            else moveToVideo($vid);    
        }
    });
});
  • 写回答

2条回答 默认 最新

  • dongsheng8664 2015-01-21 11:38
    关注

    What is the $content variable? It looks like it will use that one variable for all bindings.

    If it's just the URL set in the hidden-url div, then you want to add the binding to each selector meeting your criteria.

    jQuery('.multivideo-center-play-btn, .multivideo-preview').each(function(){
        var _self = jQuery(this);
        var $vid = jQuery(this).parent();
        _self.bind('click',function(){
            if(_self.parent().find(".hidden-url").text() != ""){
                if ($vid.hasClass('active') || isAMobile){
                    playVideo($vid);
                } else {
                    moveToVideo($vid);
                }
            } else {
                moveToVideo($vid);
            }
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计