この記事では、JavaScriptの正規表現の検索()の使用について説明します。参照のためにそれを共有してください。
特定の例コードは次のとおりです。
コードコピーは次のとおりです。
<html>
<head>
<title> search()JavaScriptの正規表現のインスタンス</title>
<Meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<script type = "text/javascript" src = "jquery-1.8.2.min.js"> </scrip>
<script type = "text/javascript">
$(function(){
$( "button")。クリック(function(){
var str = $( "p")。text();
var reg = /wang meiren /;
num = str.search(reg);
num ++;
$( "ul")。テキスト( "wang meirenは2番目の" + num + "bit"に表示されます);
});
});
</script>
<style type = "text/css">
h5 {color:blue;}
</style>
</head>
<body>
<h5>「ミス・ワン」が表示される場所を見つけます</h5>
<p>これは王の写真ですか?とても美しい</p>
<ボタン>私をクリックしてサプライズ</button>
<ul> </ul>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。