Latest web development tutorials
×

JavaScript & HTML DOM คู่มืออ้างอิง

ภาพรวม

JavaScript วัตถุ

JavaScript Array วัตถุ JavaScript Boolean วัตถุ JavaScript Date วัตถุ JavaScript Math วัตถุ JavaScript Number วัตถุ JavaScript String วัตถุ JavaScript RegExp วัตถุ JavaScript อสังหาริมทรัพย์ทั่วโลก / ฟังก์ชั่น JavaScript ผู้ประกอบการ

Browser วัตถุ

Window วัตถุ Navigator วัตถุ Screen วัตถุ History วัตถุ Location วัตถุ

DOM วัตถุ

HTML DOM Document วัตถุ HTML DOM วัตถุธาตุ HTML DOM แอตทริบิวต์วัตถุ HTML DOM วัตถุที่จัดกิจกรรม

HTML วัตถุ

<a> <area> <audio> <base> <blockquote> <body> <button> <canvas> <col> <colgroup> <datalist> <del> <details> <dialog> <embed> <fieldset> <form> <iframe> <frameset > <img> <ins> <input> - button <input> - checkbox <input> - color <input> - date <input> - datetime <input> - datetime-local <input> - email <input> - file <input> - hidden <input> - image <input> - month <input> - number <input> - range <input> - password <input> - radio <input> - reset <input> - search <input> - submit <input> - text <input> - time <input> - url <input> - week <keygen> <link> <label> <legend> <li> <map> <menu> <menuItem> <meta> <meter> <object> <ol> <optgroup> <option> <param> <progress> <q> <script> <select> <source> <style> <table> <td> <th> <tr> <textarea> <title> <time> <track> <video>

ทดสอบ JavaScript () วิธีการ

อ้างอิงวัตถุ RegExp วัตถุ JavaScript นิพจน์ทั่วไป

ความหมายและการใช้งาน

การทดสอบ () วิธีการที่ใช้ในการตรวจสอบว่าเป็นสายตรงกับรูปแบบ

หากค่าการจับคู่สายกลับจริงมิฉะนั้นก็จะส่งกลับเท็จ

ไวยากรณ์

RegExpObject.test(string)

参数 描述
string 必需。要检测的字符串。


สนับสนุนเบราว์เซอร์

Internet ExplorerFirefoxOperaGoogle ChromeSafari

เบราว์เซอร์ที่สำคัญทั้งหมดสนับสนุนการทดสอบ () วิธีการ


ตัวอย่าง

ตัวอย่าง

ในการค้นหาทั่วโลกสำหรับสตริง "สวัสดี" และ "W3CSchool" สตริง:

<script>

var str="Hello world!";
//look for "Hello"
var patt=/Hello/g;
var result=patt.test(str);
document.write("Returned value: " + result);

//look for "W3CSchool"
patt=/W3CSchool/g;
result=patt.test(str);
document.write("<br>Returned value: " + result);

</script>

ตัวอย่างของการส่งออกดังกล่าวข้างต้น:

Returned value: true
Returned value: false

ลอง»


อ้างอิงวัตถุ RegExp วัตถุ JavaScript นิพจน์ทั่วไป