0

我有这段 JS:

var count = $(".parent a").length;
$(".parent div").width(function(){
    return ($(".parent").width()/count)-5;
}).css("margin-right","5px");

但它似乎不适用于我的网站,即使它在JSFiddle上运行良好

我用了"http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"

但是没有用。

我的网站上没有任何其他脚本,因为我刚刚启动它。

只是使用错误插件的情况吗?


更新

这是我的完整代码:

http://jsfiddle.net/WeQwc/9/

4

2 回答 2

1

你需要 jQuery,而不是 jQueryUI。

http://code.jquery.com/jquery-latest.min.js

<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<script type="text/javascript">
  $(function() {
    var count = $(".parent a").length;
    $(".parent div").width(function(){
        return ($(".parent").width()/count)-5;
    }).css("margin-right","5px");
  });
</script>

只是为了澄清为什么会这样,用 $(function(){...}); 包围你的 jQuery 代码。意味着它只会在页面完成加载后运行。因此,如果您正在对 html 元素进行操作,这会很有用。你会注意到你的 jFiddle JavaScript 运行“onLoad”,它工作的原因:)

于 2013-10-22T08:03:31.120 回答
1

目前您只使用jQuery UIjs 文件

http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js

您需要先使用 core jQuerymin js 文件,然后再使用jQuery UIjs 文件。

http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js
于 2013-10-22T08:04:17.460 回答