บทความนี้อธิบายวิธีการของ JS ในการค้นหา Baidu และ Bing ในเวลาเดียวกัน แบ่งปันสำหรับการอ้างอิงของคุณ รายละเอียดมีดังนี้:
ที่นี่เราตระหนักถึงฟังก์ชั่นของการค้นหา Baidu และ Bing ในเวลาเดียวกันป้อนคำหลักคลิกปุ่ม "ค้นหา" และผลลัพธ์ของเครื่องมือค้นหาทั้งสองจะถูกเปิดในหน้าเดียวกันซึ่งสะดวก
บันทึกไฟล์ HTM สองไฟล์ต่อไปนี้วางไว้ในโฟลเดอร์เดียวกันและเปิดไฟล์แรก
รหัสสำหรับ index.htm:
คัดลอกรหัสดังนี้: <! Doctype html public "-// w3c // dtd html 4.01 transitional // en" >/
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<title> ค้นหา Baidu และ Bing ในเวลาเดียวกัน </title>
<meta http-equiv = "คำหลัก" เนื้อหา = "ค้นหา baidu และ bing ในเวลาเดียวกัน">>
<meta http-equiv = "คำอธิบาย" content = "ค้นหา baidu และ bing ในเวลาเดียวกัน">>>
</head>
<!-<body style = "text-allign: center;">
-
<frameset rows = "30%, 70%">
<frame src = "keleyi.htm">
</frame>
<frameset cols = "45%, 45%">
<frame id = "baiduframe" name = "baiduframe" src = "images/baidu.jpg"> </frame>
<frame id = "bingframe" name = "bingframe" src = "images/baidu.jpg"> </frame>
</frameset>
</frameset>
<!-<iframe id = "baiduframe"> </iframe>
<iframe id = "bingframe"> </iframe>
</body>->
</html>
ชื่อไฟล์ที่สองคือ keleyi.htm
รหัสของ keleyi.htm มีดังนี้:
คัดลอกรหัสดังนี้: <! Doctype html public "-// w3c // dtd html 4.01 transitional // en" >/
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<title> ค้นหา Baidu และ Bing ในเวลาเดียวกัน </title>
<meta http-equiv = "คำหลัก" เนื้อหา = "ค้นหา baidu และ bing ในเวลาเดียวกัน">>
<meta http-equiv = "คำอธิบาย" content = "ค้นหา baidu และ bing ในเวลาเดียวกัน">>>
<!-<link rel = "stylesheet" type = "text/css" href = "./ styles.css">->
<script type = "text/javascript">
ฟังก์ชั่น $ (id) {
ส่งคืน document.getElementById (id);
-
ฟังก์ชัน MixSearch () {
var okeyword = $ ("คำหลัก");
var oform = $ ("searchform");
// ส่งไปยัง Baidu เพื่อสร้างพารามิเตอร์ที่อยู่
Oform.action = "http://www.baidu.com/s";
okeyword.name = "wd";
Oform.method = "Get";
Oform.target = "Baiduframe";
Oform.submit ();
// ส่งไปยัง Bing สร้างพารามิเตอร์ที่อยู่
Oform.action = "http://hk.bing.com/search";
Okeyword.name = "q";
Oform.method = "Get";
Oform.target = "BingFrame";
Oform.submit ();
-
</script>
</head>
<body style = "text-allign: center;">
<form action = "" id = "searchform" method = "get" target = "baiduframe">
<อินพุต type = "text" id = "คำหลัก" name = "wd" value = "" />>
<อินพุต type = "button" value = "search ~" onclick = "mixsearch ();" -
</form>
<HR />
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน