2016-08-03 48 views
0

後鏈接URL的按鈕這是我的代碼:創建可輸入

<br> 
    < button onclick="myFunction()">LOLNEXUS< /button> 
    function myFunction() { 
    var person = prompt ("Please enter your summoner name", ""); 

    if (person != null) { 
    document.getElementById("demo").innerHTML = 
    "http://www.lolnexus.com/NA/search?name="+ person; 
    } 

我的問題是我怎麼有他們進入加入該鏈接,變成了一個URL的名字嗎?

回答

0

假設你有一個

<a href="" id="demo">Custom link</a> 
頁面上

。 在它上面調用innerHTML會修改鏈接的內容,所以只會顯示url。爲了把這個網址爲紐帶,你可以使用

document.getElementById("demo").setAttribute("href", "http://www.lolnexus.com/NA/search?name="+ person); 
0
<a href="" id="demo">Custom link</a> 

<button onclick = "myFunction()" > LOLNEXUS < /button> //按鈕

//函數開始

function myFunction() { 
    var person = prompt("Please enter your summoner name", ""); 

    if (person != null) { 
     var url = "http://www.lolnexus.com/NA/search?name=" + person; 
     $('#demo').attr('href', url); //Replace the url 

    } 
}