ホームページ  >  記事  >  ウェブフロントエンド  >  jquery がそれぞれオブジェクトを取得する方法の詳細な例

jquery がそれぞれオブジェクトを取得する方法の詳細な例

伊谢尔伦
伊谢尔伦オリジナル
2017-07-19 14:08:181445ブラウズ

JQuery がオブジェクトを取得する方法

$('#id'): 要素の ID を通して

$('tagName'): 要素のタグ名を通して

$('tagName tagName'): を通して要素の ID タグ名、例: $('ul li')

$('tagName#id): 要素の ID とタグ名を通じて

$(':checkbox'): 入力タイプがチェックボックスであるすべての要素を取得します' :


<input type="checkbox" name="appetizers"

 value="imperial"/>

$(&#39;span[price] input[type=text]&#39;) :拿取下面的input元素

<span price="3">
<input type="text" name="imperial.quantity"
         disabled="disabled" value="1"/>
</span>

$(&#39;p&#39;,$(this).parents(&#39;p:first&#39;)):拿取该p的上(至少都是父节点)的第一个p节点

$(&#39;~ span:first&#39;,this): locates the first sibling of this that&#39;s a <span> element.

遅延読み込み js ファイル: $.getScript

例:

Html ファイル:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>$.getScript Example</title>
  <link rel="stylesheet" type="text/css" href="../common.css">
  <script type="text/javascript"
      src="../scripts/jquery-1.2.1.js"></script>
  <script type="text/javascript">
   $(function(){
    $(&#39;#loadButton&#39;).click(function(){
     $.getScript(//在Firefox/3.0.1中会出现一个错误(语法错误,定义的变量不起作用,ff2没问题)
      &#39;new.stuff.js&#39;//,function(){$(&#39;#inspectButton&#39;).click()}
     );
    });
    $(&#39;#inspectButton&#39;).click(function(){
     someFunction(someVariable);
  test()
    });
   });
  </script>
</head>

<body>
  <button type="button" id="loadButton">Load</button>
  <button type="button" id="inspectButton">Inspect</button>
</body>
</html>

Js ファイル:


alert("I&#39;m inline!"); 

var someVariable = &#39;Value of someVariable&#39;; 

function someFunction(value) { 
alert(value); 
} 

function test() { 
alert(&#39;test&#39;); 
}

alert("I&#39;m inline!");

var someVariable = &#39;Value of someVariable&#39;;

function someFunction(value) {
alert(value);
}

function test() {
alert(&#39;test&#39;);
}

jquery配列処理:


りー

以上がjquery がそれぞれオブジェクトを取得する方法の詳細な例の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。