The first chapter of JavaScript

Source: Internet
Author: User

Ch01

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Scripts/common.js" ></script>
<body>
<div id= "Divfirst" >
</div>
<div id= "Divsecond" >
</div>
<div id= "Divthird" >
</div>
<script type= "Text/javascript" >
$ (' Divfirst '). InnerHTML = "<a href= ' http://www.baidu.com ' >go to baidu</a>";
updatehtml (' Divsecond ', ' <input type= ' text "value=" I am text box "/> ');
UPDATETEXT (' Divthird ', ' <pre> text content, not html</pre> ');
WriteHTML (' Hello, classmate! ‘);
Writep ("I am a paragraph content");
Writetable (10, 3);
WriteHTML (getDateString ());
WriteHTML ("<br>");
Writeselectlist ([' BMW ', ' Benz ', ' Audi ']);
Writelist ([' Apple ', ' banana ', ' cat ']);
</script>
<ul>
<li onmouseover= "SetColor (This, ' Red ')" onmouseout= "SetColor (This, ' white ')" >apple</li>
<li onmouseover= "SetColor (This, ' Red ')" onmouseout= "SetColor (This, ' white ')" >banana</li>
<li onmouseover= "SetColor (This, ' Red ')" onmouseout= "SetColor (This, ' white ')" >cat</li>
</ul>
</body>

ch02//getting DOM elements
var $ = function (ID) {
return document.getElementById (ID);
}

Output HTML
var writehtml = function (str) {
document.write (str);
}

Updating element HTML content
var updatehtml = function (id,html) {
$ (id). InnerHTML = html;
}

Update element text content
var updatetext = function (id,text) {
$ (id). InnerText = text;
}

Output paragraph
var writep = function (content) {
WriteHTML ("<p>" + content + "</p>");
}

Output table (row, column)
var writetable = function (row, col) {
WriteHTML ("<table border=1>")
for (var i = 0; i < row; i++) {
WriteHTML ("<tr>");
for (var j = 0; J < Col; J + +) {
WriteHTML ("<td>" + (i + 1). ToString ()
+ "line" + (j + 1). ToString () + "column </td>")
}
WriteHTML ("</tr>");
}
WriteHTML ("</table>");
}

Get current system time
var getdatestring = function () {
return new Date (). toLocaleString ();
}

Change the background color
var setcolor = function (o, color) {
O.style.backgroundcolor = color;
}

Output list
var writelist = function (arr) {
WriteHTML ("<ul>");
for (var i = 0; i < arr.length; i++) {
WriteHTML (' <li> ' + arr[i] + ' </li> ');
}
WriteHTML ("</ul");
}

Output drop-down box
var writeselectlist = function (arr) {
WriteHTML ("<select>");
for (var i = 0; i < arr.length; i++) {
WriteHTML (' <option> ' + arr[i] + ' </option> ')
}
WriteHTML ("</select>");
}

The first chapter of JavaScript

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.