


この 2 日間、特別なトピックを実行中にワイルドカードの問題が発生しました
//弹层操作 $(function(){ //视频播放 $("a[href^='#video']").each(function(index, element) { $(this).click(function(){ $(".popDiv,#videoBox1").show(); }); }); //图片 $(".imgs a:not([href^='#video'])").each(function(){ $(this).children("img").click(function(){ var src=$(this).attr("attr"); //alert(src); $("#picBox img").attr("src","images/" + src); $(".popDiv,#picBox").show(); $("#picBox img").animate({opacity:'1'},500) }); }); $(".close").click(function(){ $(".popDiv,.popBox").hide(); $(".box").css("margin","0 0 0 100%"); $("#picBox img").css({opacity:'0'},1000) }); })
問題は解決しました!このような問題がある場合は、以下の詳細な使用方法を参照してください:
1. セレクター
(1) ワイルドカード:
$("input[id^='code']");//id属性以code开始的所有input标签 $("input[id$='code']");//id属性以code结束的所有input标签 $("input[id*='code']");//id属性包含code的所有input标签 $("input[name^='code']");//name属性以code开始的所有input标签 $("input[name$='code']");//name属性以code结束的所有input标签 $("input[name*='code']");//name属性包含code的所有input标签 $("input[name*='code']").each(fuction(){ var sum=0; if($(this).val()!=""){ sum=parseInt(sum)+parseInt($(this).val()); } $("#").text(sum); })
(2) インデックスに従って
を選択します$("tbody tr:even"); //偶数のインデックスを持つすべての tr タグを選択します
$("tbody tr:odd"); //奇数のインデックスを持つすべての tr タグを選択します
(3) jqueryObj
の次段ノードの入力数を取得します。jqueryObj.children("input").length;
(4) クラス main
のラベルの子ノード配下のすべてのラベルを取得します$(".main > a");
(5)
の横のラベルを選択しますjqueryObj.next("div");//获取jqueryObj标签的后面紧邻的一个div,nextAll获取所有
2. フィルター
//not $("#code input:not([id^='code'])");//id为code标签内不包含id以code开始的所有input标签
3. イベント
//处理文本框上的键盘操作 jqueryObj.keyup(function(event){ var keyCode = event.which;//获取当前按下键盘的键值,回车键为13 }
4. ユーティリティ機能
$('#someField').val($.trim($('#someField').val()));//消除空格,语法:$.trim(value)
ps: jQuery セレクターの概要
jQuery のセレクターは非常に強力です。一般的に使用される要素検索メソッドを簡単にまとめます。
$("#myELement") ID 値が myElement と等しい要素を選択します。ID 値は繰り返すことができないため、要素
のみを取得します。
$("div") すべての div タグ要素を選択し、div 要素の配列を返します
$(".myClass") myClass クラスの CSS を使用してすべての要素を選択します
$("*") ドキュメント内のすべての要素を選択します。 結合選択にはさまざまな選択方法を使用できます。たとえば、$("#myELement,div,.myclass")
です。カスケードセレクター:
$("form input") フォーム要素内のすべての入力要素を選択します
$("#main > *") main
の ID 値を持つすべての子要素を選択します
$("label + input") すべてのラベル要素の次の入力要素ノードを選択します。テスト後、セレクターは入力ラベル
が直接続くすべての入力ラベル要素を返します。
$("#prev ~ div") 兄弟セレクター。このセレクターは、ID prev のタグ要素の同じ親要素
基本フィルターセレクター:
$("tr:first") すべての tr 要素の最初の要素を選択します
$("tr:last") すべての tr 要素の最後の
を選択します
$("input:not(:checked) + スパン")
フィルターアウト: チェックされたセレクターのすべての入力要素
$("tr:even") すべてのtr要素の0番目、2番目、4番目…の要素を選択します(注:選択された複数の要素は配列のため、シーケンス番号は0から始まります)
$("tr:odd") すべてのtr要素の1番目、3番目、5番目…の要素を選択します
$("td:eq(2)") すべての td 要素のうち、シリアル番号 2 の td 要素を選択します
$("td:gt(4)") td 要素内のシーケンス番号が 4 より大きいすべての td 要素を選択します
$("td:ll(4)") td 要素内のシーケンス番号が 4 未満のすべての td 要素を選択します
$(":header")
$("div:アニメーション")
コンテンツフィルターセレクター:
$("div:contains('John')") は、div 内の John テキストを含むすべての要素を選択します
$("td:empty") 空のすべての td 要素の配列を選択します (テキスト ノードは含まれません)
$("div:has(p)") p タグを含むすべての div 要素を選択します
$("td:parent") td を親ノードとするすべての要素配列を選択します
ビジュアルフィルターセレクター:
$("div:hidden") 非表示の div 要素をすべて選択します
$("div:visible") 表示されているすべての div 要素を選択します
属性フィルターセレクター:
$("div[id]") id 属性を含むすべての div 要素を選択します
$("input[name='newsletter']") name 属性が 'newsletter' と等しいすべての入力要素を選択します
$("input[name!='newsletter']") は、name 属性が 'newsletter' と等しくないすべての入力要素を選択します
$("input[name^='news']") name 属性が 'news' で始まるすべての入力要素を選択します
$("input[name$='news']") name 属性が 'news' で終わるすべての入力要素を選択します
$("input[name*='man']") name 属性に 'news' が含まれる入力要素をすべて選択します
$("input[id][name$='man']") このセレクターは、id 属性を含み、属性が man
子要素フィルターセレクター:
$("ul li:nth-child(2)"),$("ul li:nth-child(odd)"),$("ul li:nth-child(3n + 1)")
$("div span:first-child") 返回所有的div元素的第一个子节点的数组
$("div span:last-child") 返回所有的div元素的最后一个节点的数组
$("div button:only-child") 返回所有的div中只有唯一一个子节点的所有子节点的数组
表单元素选择器:
$(":input") 选择所有的表单输入元素,包括input, textarea, select 和 button
$(":text") 选择所有的text input元素
$(":password") 选择所有的password input元素
$(":radio") 选择所有的radio input元素
$(":checkbox") 选择所有的checkbox input元素
$(":submit") 选择所有的submit input元素
$(":image") 选择所有的image input元素
$(":reset") 选择所有的reset input元素
$(":button") 选择所有的button input元素
$(":file") 选择所有的file input元素
$(":hidden") 选择所有类型为hidden的input元素或表单的隐藏域
表单元素过滤选择器:
$(":enabled") 选择所有的可操作的表单元素
$(":disabled") 选择所有的不可操作的表单元素
$(":checked") 选择所有的被checked的表单元素
$("select option:selected") 选择所有的select 的子元素中被selected的元素
选取一个 name 为”S_03_22″的input text框的上一个td的text值
$(”input[@ name =S_03_22]“).parent().prev().text()
名字以”S_”开始,并且不是以”_R”结尾的
$(”input[@ name ^='S_']“).not(”[@ name $='_R']“)
一个名为 radio_01的radio所选的值
$(”input[@ name =radio_01][@checked]“).val();
$("A B") 查找A元素下面的所有子节点,包括非直接子节点
$("A>B") 查找A元素下面的直接子节点
$("A+B") 查找A元素后面的兄弟节点,包括非直接子节点
$("A~B") 查找A元素后面的兄弟节点,不包括非直接子节点
1. $("A B") 查找A元素下面的所有子节点,包括非直接子节点
例子:找到表单中所有的 input 元素
HTML 代码:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery 代码:
$("form input")
结果:
[ <input name="name" />, <input name="newsletter" /> ]
2. $("A>B") 查找A元素下面的直接子节点
例子:匹配表单中所有的子级input元素。
HTML 代码:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery 代码:
$("form > input")
结果:
[ <input name="name" /> ]
3. $("A+B") 查找A元素后面的兄弟节点,包括非直接子节点
例子:匹配所有跟在 label 后面的 input 元素
HTML 代码:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery 代码:
$("label + input")
结果:
[ <input name="name" />, <input name="newsletter" /> ]
4. $("A~B") 查找A元素后面的兄弟节点,不包括非直接子节点
例子:找到所有与表单同辈的 input 元素
HTML 代码:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery 代码:
$("form ~ input")
结果:
[ <input name="none" /> ]

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
