如何在 jQuery 中檢查一個字串是否包含子字串?
jQuery :contains() 選擇器用於檢查一個字串是否在 jQuery 中包含子字串。
在 contains() 方法中設定要搜尋的子字串,如下所示
$(document).ready(function(){
$("p:contains(Video)").css("background-color", "blue");
});現在,讓我們瞭解完整的程式碼來檢查一個字串是否包含子字串
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:contains(Video)").css("background-color", "blue");
});
</script>
</head>
<body>
<h1>Tutorialspoint</h1>
<p>This is demo text.</p>
<p>Free Tutorials</p>
<p>Free Video Tutorials</p>
</body>
</html>
廣告
資料結構
網路
關係型資料庫
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP