1

ユーザーが a の値を変更したときにリンクを編集したいのですが、<input type="text">うまくいきません。私のHTML:

    <head>
    <link rel="stylesheet" href="styles.css" />
    <script type="text/javascript">
    function updateGiveLink() {
        document.getElementById("givelink").innerHTML = "http://kroltan.eliti.com.br/diamonds/?give="+document.getElementsById("givetext").value;
        document.getElementById("givelink").href = "http://kroltan.eliti.com.br/diamonds/?give="+document.getElementsById("givetext").value;
    }
    </script>
    </head>
    <input type="text" placeholder="Minecraft username" name="give" id="givetext" onchange="updateGiveLink()" /> 
    <a id="givelink" href="http://kroltan.eliti.com.br/diamonds/?give=Player">http://kroltan.eliti.com.br/diamonds/?give=Player</a>

これは の URL と表示テキストを変更して、URLgivelink?give=一部にテキスト フィールドの値を持たせることになっていますgivetext。しかし、期待どおりに機能していません。代わりに、何もしません。私も and を使用しonkeyuponinputみました (これらは別の関連する質問で見ました)、成功しませんでした。

4

2 に答える 2

2

document.getElementById("givetext").valueそれはあなたが持っていたgetElementsByはずですs

デモを使用した作業コードonkeyup

于 2012-06-17T15:38:09.140 に答える
1

document.getElementsById を使用したため、構文エラーが発生している可能性がありますが、document.getElementById である必要があります。

于 2012-06-17T15:38:30.840 に答える