jQuery has()
此方法篩選匹配元素集合中包含特定後代的元素。
返回值是一個jQuery物件。
語法結構一:
[JavaScript] 純文字檢視 複製程式碼$(selector).has(expr)
引數解析:
expr:字串選擇器。
jQuery1.4版本新增。
語法結構二:
[JavaScript] 純文字檢視 複製程式碼$(selector).has(element)
引數解析:
element:用於匹配元素的DOM元素。
jQuery1.4版本新增。
程式碼例項:
[HTML] 純文字檢視 複製程式碼執行程式碼<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("li").has("span").css("color","blue") }) </script> </head> <body> <div> <ul> <li><span>螞蟻部落一</span></li> <li>螞蟻部落二</li> <li>螞蟻部落三</li> <li>螞蟻部落四</li> </ul> </div> </body> </html>
可以將含有span元素的li元素字型顏色設定為藍色。
[HTML] 純文字檢視 複製程式碼執行程式碼<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(document).ready(function () { var span=document.getElementsByTagName("span")[0]; $("li").has(span).css("color", "blue") }) </script> </head> <body> <div> <ul> <li><span>螞蟻部落一</span></li> <li>螞蟻部落二</li> <li>螞蟻部落三</li> <li>螞蟻部落四</li> </ul> </div> </body> </html>
上面程式碼的功能是一樣的,只不過引數是一個dom物件。
相關文章
- [CSS 3] :has()CSS
- RuntimeError: An attempt has been made to start a new process before the current process hasError
- Reflect.has() 方法
- yarn certificate has expiredYarn
- Proxy handler.has() 方法
- Process object has no attribute '_popen'Object
- MySQL server has gone awayMySqlServerGo
- ‘dict‘ object has no attribute ‘iteritems‘Object
- Input報錯“Form elements must have labels: Element has no title attribute Element has no placeholde”ORM
- jQuery初探:自制jQueryjQuery
- 'This NSPersistentStoreCoordinator has no persistent stores 報錯
- ORA-28001:the password has expired
- Window Application has "update" key wordsAPP
- Teamcenter 《POM has not start》處理
- “setting.xml” has syntax errorsXMLError
- Your VM has become "inaccessible.
- Jeff Bezos Has Nothing On Tom Nook
- AttributeError: 'Settings' object has no attribute 'HBase'ErrorObject
- 我的’jQuery’和jQueryjQuery
- 問題MySQL server has gone awayMySqlServerGo
- akka-typed(3) - PersistentActor has EventSourcedBehavior
- The version given was unknown or has no registered routes.
- AttributeError: module ‘requests‘ has no attribute ‘_version_‘Error
- Computed property "isShowDialog" was assigned to but it has no setter.
- CSS父級選擇器 :has()CSS
- ‘FirewallD‘ object has no attribute ‘path‘ 、‘fw‘、is not registeredObject
- 【坑】Tkinter ‘NoneType‘ object has no attribute ‘destroy‘NoneObject
- jQueryjQuery
- jQuery入門(三)--- jQuery語法jQuery
- jquery列印頁面(jquery.jqprint)jQuery
- JQuery模板外掛-jquery.tmpljQuery
- Uncaught SyntaxError: Identifier 'Geometry' has already been declaredErrorIDE
- has(),find()以及filter()方法的區別Filter
- 淺析Is-a,Has-a與like-a
- EA has continued to update Madden 21 Ultimate Team
- React-Native ‘WKWebView` has no propType for native propReactWebView
- module ‘tensorflow‘ has no attribute ‘get_default_graph‘
- module ‘h5py‘ has no attribute ‘File‘H5
- JQuery基本知識彙總;JQuery常用方法;淺入瞭解JQueryjQuery