Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery元素选择_Javascript_Jquery - Fatal编程技术网

Javascript jquery元素选择

Javascript jquery元素选择,javascript,jquery,Javascript,Jquery,我知道我可以使用以下语法选择元素,但还有什么其他方法可用?当我试图确定其他人时,我不知道要搜索什么。还有,有没有通过通配符选择元素的方法 //Selection by the element's ID $('#mybutton').on('click', function (e) { alert('mybutton clicked'); }); //Select by the element's css class $('.mybuttonclass').on('

我知道我可以使用以下语法选择元素,但还有什么其他方法可用?当我试图确定其他人时,我不知道要搜索什么。还有,有没有通过通配符选择元素的方法

  //Selection by the element's ID
  $('#mybutton').on('click', function (e) {
     alert('mybutton clicked');
  });

  //Select by the element's css class
  $('.mybuttonclass').on('click', function (e) {
     alert('mybutton clicked');
  });

  //Selection of a tag with name of delete found within a table
  $('table').on('click','a[name=delete]', function (e) {
     alert('table link clicked');
  });
因此,我可以使用名称、ID或类。还有其他方法吗?谷歌搜索词或链接会很有帮助

编辑:


我在文档中找到了selectors页面,但认为该页面不适用。我很难理解这一页,以为它是指别的东西。这就是为什么我在寻找另一个搜索词,因为所有的东西都在显示“选择器”,我不认为这是我需要的。显然,我毕竟是在正确的位置。

您正在寻找的是。

jQuery中有很多选择器!请看这里

我发现导航有点容易。

老实说,有关于JQuery选择器的最佳文档,您必须查看。

谷歌搜索词:。在谷歌中键入您的问题标题:on捕获在dom中冒泡的事件,因此,您需要在堆栈中高于动态元素的永久元素上使用它。我知道这不是你的问题,只是把它扔出去。假设表格始终在页面上,您的唯一一个看起来应该可以工作的是最后一个。我找到了选择器页面,但认为这不是我要找的,因此我提出问题的原因。我想我没想到会有这么多的选择,我被我找到的页面弄糊涂了。作为jQuery的新手,我希望有一个更简单的解释,因为我没有意识到可以应用的复杂性。老实说,没有。它缺少许多选择器,并且没有多少细节。老实说,w3schools是一个。为什么不链接到jquery?老实说,对于刚开始使用jquery的人来说,这么多就足够了。否则“太多的厨师会破坏食物”。我同意你的观点@MehulHingu。这个页面对我来说更清晰一些,因为我对jQuery(以及javascript)相当陌生。这些例子对我更有意义。我发现jQuery文档有点晦涩难懂,这是使用W3的人必须阅读的。我曾经自己用过它,在找到它之后,我立即停止了,这里给出了一些非常好的观点。这是我最初搜索时期望找到的。谢谢@PranayRana
    Selector    Example       Selects
    *           $("*")                All elements
    #id         $("#lastname")  The element with id=lastname
    .class  $(".intro") All elements with class="intro"
    element $("p")  All p elements
   .class.class $(".intro.demo")    All elements with the classes "intro" and "demo"

    :first  $("p:first")    The first p element
    :last   $("p:last") The last p element
    :even   $("tr:even")    All even tr elements
    :odd    $("tr:odd") All odd tr elements

    :eq(index)  $("ul li:eq(3)")    The fourth element in a list (index starts at 0)
    :gt(no) $("ul li:gt(3)")    List elements with an index greater than 3
    :lt(no) $("ul li:lt(3)")    List elements with an index less than 3
  :not(selector)$("input:not(:empty)")  All input elements that are not empty

    :header $(":header")    All header elements h1, h2 ...
    :animated   $(":animated")  All animated elements

 :contains(text)$(":contains('W3Schools')") All elements which contains the text
    :empty  $(":empty") All elements with no child (elements) nodes
    :hidden $("p:hidden")   All hidden p elements
    :visible    $("table:visible")  All visible tables

    s1,s2,s3    $("th,td,.intro")   All elements with matching selectors

[attribute] $("[href]") All elements with a href attribute
[attribute=value]$("[href='default.htm']")  All elements with a href attribute value equal to "default.htm"
[attribute!=value]$("[href!='default.htm']")    All elements with a href attribute value not equal to "default.htm"
[attribute$=value]$("[href$='.jpg']")   All elements with a href attribute value ending with ".jpg"

    :input  $(":input") All input elements
    :text   $(":text")  All input elements with type="text"
    :password   $(":password")  All input elements with type="password"
    :radio  $(":radio") All input elements with type="radio"
    :checkbox   $(":checkbox")  All input elements with type="checkbox"
    :submit $(":submit")    All input elements with type="submit"
    :reset  $(":reset") All input elements with type="reset"
    :button $(":button")    All input elements with type="button"
    :image  $(":image") All input elements with type="image"
    :file   $(":file")  All input elements with type="file"

    :enabled    $(":enabled")   All enabled input elements
    :disabled   $(":disabled")  All disabled input elements
    :selected   $(":selected")  All selected input elements
    :checked    $(":checked")   All checked input elements