2016-08-03 11 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になって入力した名前を持っているんですか?あなたのページの

<a href="" id="demo">Custom link</a> 

を持っていると仮定すると

答えて

0

。 innerHTMLを呼び出すと、リンクの内容が変更されるため、URLのみが表示されます。リンクとしてこの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 

    } 
} 
を開始し使用することができます