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物件。
相關文章
- jQuery :has()jQuery
- oracle hasOracle
- AttributeError: 'dict' object has no attribute 'has_key'ErrorObject
- oracle has a disk HB, but no network HB, DHB has r cfg , wrtcntOracle
- MySQL server has gone awayMySqlServerGo
- Python has two GILsPython
- RuntimeError: An attempt has been made to start a new process before the current process hasError
- Process object has no attribute '_popen'Object
- ‘dict‘ object has no attribute ‘iteritems‘Object
- He also has best iphone casesiPhone
- An out of memory error has occurred.Error
- How has JBuilder 8 source codeUI
- getOutputStream() has already been called
- Teamcenter 《POM has not start》處理
- “setting.xml” has syntax errorsXMLError
- akka-typed(3) - PersistentActor has EventSourcedBehavior
- 問題MySQL server has gone awayMySqlServerGo
- Window Application has "update" key wordsAPP
- Uncaught TypeError: Object # has no method 'load'ErrorObject
- 關於“Client 000 has status ‘not modifiable’”client
- SELinux has to be disabled on RHEL/OEL 5Linux
- has(),find()以及filter()方法的區別Filter
- ‘FirewallD‘ object has no attribute ‘path‘ 、‘fw‘、is not registeredObject
- An internal error has occurred. Java heap spaceErrorJava
- AttributeError: 'module' object has no attribute 'lock'ErrorObject
- MySQL server has gone away 解決方案MySqlServerGo
- The installer has not detected any Oracle 10.2.0.4.0Oracle
- JIRA startup failed, JIRA has been locked.AI
- InnoDB Plugin has been upgraded to version 1.0.8Plugin
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!REMIDE
- module ‘h5py‘ has no attribute ‘File‘H5
- 【坑】Tkinter ‘NoneType‘ object has no attribute ‘destroy‘NoneObject
- AttributeError: module ‘requests‘ has no attribute ‘_version_‘Error
- AttributeError: 'Settings' object has no attribute 'HBase'ErrorObject
- 專案使用guzzleHttp報錯:certificate has expiredHTTP
- 解決The jar file has no source attachment問題JAR
- svn“Previous operation has not finished; run 'cleanup' if it was interrupted
- “Transport security has blocked a cleartext HTTP (http ) resource loBloCHTTP