duanli9569
duanli9569
采纳率100%
2016-07-11 03:27 浏览 41

如何修复WordPress自定义页面中的“TypeError:$(...)。chained is not function”错误?

I create a custom WordPress page via widget where I want to active a widget using this code

jQuery(document).ready(function($) {
    /* For $.chained.js */
    $("#series").chained("#mark");
    $("#model").chained("#series");
    $("#engine").chained("#series, #model");

    return;
    /* Show button after each pulldown has a value. */
    $("#engine").bind("change", function(event) {
        if ("" != $("option:selected", this).val() && "" != $("option:selected", $("#model")).val()) {
            $("#button").fadeIn();
        } else {
            $("#button").hide();          
        }
    })
});

When I activated the widget, that code can work fine but if I inactivated the widget that code show error TypeError: $(....).chained is not function. So how to fix this ? Thank you ..

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答 默认 最新

  • 已采纳
    dongshenchi5364 dongshenchi5364 2016-07-11 03:48

    This happens because the "Chained Selects" plugin source is not included:

    function enqueue_stuff(){
        wp_enqueue_script('chainedjs', 'https://raw.githubusercontent.com/tuupola/jquery_chained/master/jquery.chained.remote.min.js', array('jquery'), false, true);    
    }
    add_action('wp_enqueue_scripts', 'enqueue_stuff');
    
    点赞 评论 复制链接分享

相关推荐