Home > HTML, Javascript > JavaScript on the web

JavaScript on the web

在Head中引用Javascript文件(像引用CSS文件一樣):

  • <head><script type=”text/javascript” src=”script.js”></script></head>

HTML中表單與Javascript的交互(HTML部份):

  • <button onclick=”functionName(‘input’)”>Button Name</button>
  • <form name=”formName”>
    • <label for=”inputName”>labelName</label>
    • <input type=”text” name=”textinput”>
    • <select name=”selectName”>
      <option value=”A” selected>A</option>
      <option value=”B”>B</option>
      </select>
    • <input type=”radio” name=”radioName” value=”choice1″ checked>Choice 1<br>
      <input type=”radio” name=”radioName” value=”choice2″ checked>Choice 2<br>
    • <input type=”checkbox” name=”checkboxName” >
    • <input type=”button” value=”name” onclick=”function()”>

    </form>

HTML中表單與Javascript的交互(JS部份):

  • document.getElementById(“divID”).innerHTML += HTMLcode; //將JS結果寫入HTML
  • var variable= document.formName.textinput.value; //將網頁表單text內容寫入JS
  • for (var i=0; i < document.formName.radioName.length; i++) {
    if (document.formName.radioName[i].checked) {
    newvariable = document.formName.radioName[i].value; //將網頁表單radio內容寫入JS
    }
Categories: HTML, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: