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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)