0

I want to change the text of the div "result" when a person writes something in the text box and make it the text the user wrote. is anyone pro/smart/knowledgeable enough to help me? I m new to java script so please help me. Here is the code:

<!DOCTYPE HTML>
<html>
<head>

<script>
function updateText(text){
document.getElementById("result").innerHTML =text;
}
}</script>

</head>
<body>

<div id="text">
Write to change:<input id="slide" type="text" value=""
onchange="updateText(this.value);" />


</div>
<div id="result" style="height:40px;width:40px;border:1px solid #999"></div>
<br/>
</body>

</html>

i would also like to know how to insert text which the user wrote into a prompt box into that element of the page.

4

1 に答える 1

0

コードで余分な '}' を 1 つ使用したという事実を除いて、コードはまったく問題ありません。

<!DOCTYPE HTML>
    <html>
    <head>    
    <script>
    function updateText(text){
    document.getElementById("result").innerHTML =text;
    }
    </script>    
    </head>
    <body>    
    <div id="text">
    Write to change:<input id="slide" type="text" value=""
    onchange="updateText(this.value);" />
    </div>
    <div id="result" style="height:40px;width:40px;border:1px solid #999"></div>
    <br/>
    </body>    
    </html>

ただし、ブラウザー画面では、コントロールをテキストフィールドから離した場合にのみ出力を確認できます。何らかの入力を行った後、ブラウザの別の場所をクリックしてみてください。

于 2013-04-24T05:33:21.843 に答える