使用链式jQuery插件 [英] Using Chained Jquery plugin

查看:91
本文介绍了使用链式jQuery插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在CakePhp( http://www.appelsiini.net /projects/chained ) 我使用Jquery测试警报,并且该警报有效,但只是链式插件无法正常工作.我正在尝试使用他们的代码在其网站上遵循该示例.如果要查看我的页面,请访问 http://team.southpacificavionics.com/customers/test 登录:访客 密码:密码

I am trying to use the remote Chained plugin in CakePhp (http://www.appelsiini.net/projects/chained) I used Jquery to test an alert and that works but just the chained plugin is not working. I am trying to follow the example on their website using their code. If you want to view my page go to http://team.southpacificavionics.com/customers/test login: guest password: password

jquery.chained.remote.min.js

jquery.chained.remote.min.js

/*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function(a){"use strict";a.fn.remoteChained=function(b){var c=a.extend({},a.fn.remoteChained.defaults,b);return c.loading&&(c.clear=!0),this.each(function(){function b(b){var c=a(":selected",d).val();a("option",d).remove();var e=[];if(a.isArray(b))e=a.isArray(b[0])?b:a.map(b,function(b){return a.map(b,function(a,b){return[[b,a]]})});else for(var f in b)b.hasOwnProperty(f)&&e.push([f,b[f]]);for(var g=0;g!==e.length;g++){var h=e[g][0],i=e[g][1];if("selected"!==h){var j=a("<option />").val(h).append(i);a(d).append(j)}else c=i}a(d).children().each(function(){a(this).val()===c+""&&a(this).attr("selected","selected")}),1===a("option",d).size()&&""===a(d).val()?a(d).prop("disabled",!0):a(d).prop("disabled",!1)}var d=this,e=!1;a(c.parents).each(function(){a(this).bind("change",function(){var f={};a(c.parents).each(function(){var b=a(this).attr(c.attribute),e=(a(this).is("select")?a(":selected",this):a(this)).val();f[b]=e,c.depends&&a(c.depends).each(function(){if(d!==this){var b=a(this).attr(c.attribute),e=a(this).val();f[b]=e}})}),e&&a.isFunction(e.abort)&&(e.abort(),e=!1),c.clear&&(c.loading?b.call(d,{"":c.loading}):a("option",d).remove(),a(d).trigger("change")),e=a.getJSON(c.url,f,function(c){b.call(d,c),a(d).trigger("change")})}),c.bootstrap&&(b.call(d,c.bootstrap),c.bootstrap=null)})})},a.fn.remoteChainedTo=a.fn.remoteChained,a.fn.remoteChained.defaults={attribute:"name",depends:null,bootstrap:null,loading:null,clear:!1}}(window.jQuery||window.Zepto,window,document);

test.ctp

<?php echo $this->Html->script('jquery.min'); ?>
<?php echo $this->Html->script('jquery.chained.remote.min'); ?>


<script type="text/javascript">
    $(document).ready(function () {
        alert('java is working');
    });
</script>

<select id="mark" name="mark">
  <option value="">--</option>
  <option value="bmw">BMW</option>
  <option value="audi">Audi</option>
</select>
<select id="series" name="series">
  <option value="">--</option>
  <option value="series-3" class="bmw">3 series</option>
  <option value="series-5" class="bmw">5 series</option>
  <option value="series-6" class="bmw">6 series</option>
  <option value="a3" class="audi">A3</option>
  <option value="a4" class="audi">A4</option>
  <option value="a5" class="audi">A5</option>
</select>

<script>
(function() { 
    $("#series").chainedTo("#mark");
});
</script>

推荐答案

这与CakePHP无关,它是一个客户端javascript库.

This has nothing to do with CakePHP really - it's a client-side javascript library.

但是您有两个问题,第一个:

But you have two problems, first:

(function() { 
    $("#series").chainedTo("#mark");
});

实际上不是运行中",您只是定义了一个匿名函数,该函数将被调用(如果被调用).可能应该将其仅移动到alert所在的位置:

Is not actually "running", you just defined an anonymous function that would run, if called. It should just be moved, probably, to where you're alert resides:

<script type="text/javascript">
    $(document).ready(function () {
        $("#series").chainedTo("#mark");
    });
</script>

现在它将运行,但是如果您检查了浏览器控制台,它将出现错误,例如:

Now it'll run, but if you checked the browser Console, it'll be erroring out, something like:

未捕获的TypeError:$(...).chainedTo不是函数

Uncaught TypeError: $(...).chainedTo is not a function

该库似乎未正常运行.

It looks like the library isn't running correctly.

我不确定您从何处获得了jquery链接库的源代码,但是它不是您链接的github从中获取它的页面中的当前版本:

I'm not sure where you got the source code for the jquery chained library, but it's not the current version in the page you link's github grab it from:

https://github.com/tuupola/jquery_chained/

此处列出了直接最小化版本:

A direct minimized version is listed here:

https://raw.githubusercontent.com/tuupola /jquery_chained/master/jquery.chained.min.js

这篇关于使用链式jQuery插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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