2014年6月18日 星期三

Web(3) HTML +Java Script 的HELLO WORLD with Input Tag

Sample code 如下:
<html>
 <head>
<script type='text/javascript'>
function buttonClickHandler() {
        var userName = document.getElementById("nameInput").value;
        var greetingString = "Hello, " + userName + "!";
        document.getElementById("greetingOutput").innerText = greetingString;
}
</script>
 </head>


 <body>
    <h1>Hello, world!</h1>
    <p>What's your name?</p>
    <input id="nameInput" type="text" />
    <button id="helloButton" onclick="buttonClickHandler()">Say "Hello"</button>
    <div id="greetingOutput"></div>
 </body>
</html>

結果如下

  • 程式一開始的畫面



l   TEXT BAR輸入"TEST",然後按SAY "Hello"button
顯示出Hello, TEST!的字樣。

沒有留言:

張貼留言