บทความนี้อธิบายการค้นหา () การใช้งานนิพจน์ปกติของ JavaScript แบ่งปันสำหรับการอ้างอิงของคุณ
รหัสตัวอย่างเฉพาะมีดังนี้:
การคัดลอกรหัสมีดังนี้:
<html>
<head>
<title> search () อินสแตนซ์ของ JavaScript Expression ปกติ </title>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<script type = "text/javascript" src = "jQuery-1.8.2.min.js"> </script>
<script type = "text/javascript">
$ (function () {
$ ("ปุ่ม") คลิก (ฟังก์ชัน () {
var str = $ ("p"). text ();
var reg = /wang meiren /;
num = str.search (reg);
num ++;
$ ("ul") ข้อความ ("Wang Meiren ปรากฏในครั้งที่สอง" + num + "บิต");
-
-
</script>
<style type = "text/css">
h5 {color: blue;}
</style>
</head>
<body>
<H5> ค้นหาตำแหน่งที่ "Miss Wang" ปรากฏขึ้น </h5>
<p> นี่เป็นรูปของ Wang Meiren หรือไม่? สวยมาก </p>
<button> คลิกฉันเพื่อให้ประหลาดใจ </button>
<ul></ul>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน