借用搜索引擎搜索
? ? ??
? ? ? <script>
? ? ? var link = "https://cn.bing.com/search?q=";?//默認(rèn)使用的引擎
? ? ? function myFunction2() {
? ? ? link = "https://" + document.getElementById("myinput2").value; //提取下方的input輸入
? ? ? }?
? ? ? function baidu() { link="https://baidu.com/s?wd=" ;}? //百度搜索
? ? ? function so() { link="https://so.com/s?q=" ;}??//360搜索? ? ?
? ? ? /*點(diǎn)擊a標(biāo)簽運(yùn)行*/
? ? ? function myFunction() {
? ? ? var text = document.getElementById("myinput").value;
? ? ? var newhref = link + text;? ? //將鏈接和要搜索的內(nèi)容合成賦予給變量newhref
? ? ??/*將newhref傳輸給id為"mylink"的元素,并將其的href值更改為newhref*/
? ? ? document.getElementById("mylink").setAttribute("href", newhref);
? ? ? ? ?}
? ? </script>
? ? <div>
? ? ? ? <!--搜索的內(nèi)容-->
? ? <input type="text" placeholder="輸入文本" id="myinput"></input>
? ? ? ? <!--用戶輸入引擎鏈接-->
? ? <input type="text" placeholder="輸入引擎鏈接" id="myinput2"></input>
? ? ? ?<button onclick="myFunction2()">使用</button>? //點(diǎn)擊運(yùn)行myFunction2()
? ? ? ??<!--預(yù)設(shè)引擎鏈接-->
? ? ? ? <button onclick="baidu()">百度</button>? //點(diǎn)擊運(yùn)行baidu()
? ? ? ? <button onclick="so()">360</button> //點(diǎn)擊運(yùn)行so()
? ? <a href="" onclick="myFunction()" id="mylink">查找</a> //點(diǎn)擊運(yùn)行myFunction()
? ? </div>
? ??