jQuery 1.3只选择第一个元素 [英] jQuery 1.3 only selecting the first element

查看:101
本文介绍了jQuery 1.3只选择第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是一个bug还是jQuery 1.3中的一些疯狂的新东西,我不知道,或者我刚刚疯了。

I'm not sure if this is a bug or just some crazy new thing in jQuery 1.3 that I'm unaware of, or if I've just gone crazy.

我有一个包含11个复选框的表格,我无法使用jQuery 1.3选择它们:

I have a table with 11 checkboxes in it, and I can't select them all using jQuery 1.3:

// jQuery 1.2.6
$(".myTable").find(":checkbox");  // finds 11 elements

// jQuery 1.3
$(".myTable").find(":checkbox");  // finds 1 element: the first checkbox
$(":checkbox", $(".myTable"));    // finds 1 element
$('.myTable :checkbox'));         // finds all 11 elements

如果我使用,结果是相同的。 find('*'):它只选择1.3中的第一个元素,所以它不是所特有的:复选框

The results are the same if I use .find('*'): it only picks the first element in 1.3, so it's nothing peculiar to :checkbox.

在我自己的页面上,我每次都可以重新创建,但是当我将(貌似)相关部分粘贴到JSBin中时,它可以正常工作!

On my own page, I can recreate this every time, but when I paste the (seemingly) relevant parts into JSBin, it works!

原始页面也包含Mootools,但我一直非常小心使用范围,并且jQ 1.2.6没有任何问题,所以我认为不是这样。还有其他想法吗?

The original page also has Mootools included, but I've been very careful with scoping and there weren't any issues with jQ 1.2.6, so I don't think that could be it. Any other ideas?

在有人说出来之前,使用 .find()函数非常在这种情况下,比组合选择器(。myTable:checkbox)更方便,并且不能将我的所有代码更改为该样式!

And before anyone says it, using the .find() function is very much more convenient than the combined selector (".myTable :checkbox") in this case, and changing all my code to that style isn't an option!

推荐答案

如果它确实是个bug,你应该访问jQuery bug跟踪器网站并报告它(参见 http://dev.jquery.com/ )。

If it's really a bug, you should visit the jQuery bug tracker site and report it (see http://dev.jquery.com/).

这是特别是因为1.3刚刚发布。但是,考虑到测试的数量,我强烈建议您尝试一个非常简单的网页,看看它是否真的是jQuery的问题,或者,如您所说,可能与您的其他工具(即Mootools)进行交互。一个简单的骨骼页面只有几个复选框,1.3 jQuery和你在问题中给出的代码将是理想的。

This is especially true as 1.3 has only just been released. However, given the amount of testing it's gone through, I'd strongly suggest you try a very simple web page to see if it's really a problem with jQuery or, as you suggest, a possible interaction with your other tools (i.e., Mootools). A bare bones page with just a couple of check boxes, the 1.3 jQuery and the code you've given in your question would be ideal.

只有它仍然是一个问题然后我会在jQuery上提出一个错误,否则我会从各种讨论组开始,看看他们是否可以提供帮助。

Only if it's still an issue then would I raise a bug on jQuery, otherwise I'd start with the various discussion groups to see if they can help.

例如,这段代码 实际上是有效的,所以它不太可能是jQuery的错误。

For example, this piece of code does actually work so it's unlikely to be a bug with jQuery.

<html>
  <head>
    <script type="text/javascript" src="jquery-1.3.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $(document).find(":checkbox").attr('checked',false);
        $("a").click(function(event){
          $(".myTable").find(":checkbox").attr('checked',true);
          event.preventDefault();
        });
      });
    </script>
  </head>
  <body>
    <a href="http://nowhere.com/">Click me!</a><hr>
    <table class="myTable"><tr>
      <td><input type="checkbox">One</input></td>
      <td><input type="checkbox">Two</input></td>
      <td><input type="checkbox">Three</input></td>
    </tr></table>
  </body>
</html>

这篇关于jQuery 1.3只选择第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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