js解碼和編碼.html
復制代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript的編碼和解碼</title>
<script type="text/javascript">
function gel(id) {
return document.getElementById(id);
}
window.onload = function() {
//alert(document.getElementById("span1").innerHTML
gel("btn1").onclick = function() {
alert(encodeURI(gel("span1").innerHTML));
};
gel("btn2").onclick = function() {
alert(decodeURI(gel("span1").innerHTML));
};
};
</script>
</head>
<body>
<span id="span1">瘋漢三雄起了!</span>
<input type="button" id="btn1" value="編碼後" />
<input type="button" id="btn2" value="解碼後" />
</body>
</html>
js中setInterval和setTimeout的使用.html
復制代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>js中setInterval和setTimeout的使用</title>
<script type="text/javascript">
var time = 10;
var id = 0;
function gel(id) {
return document.getElementById(id);
}
function dectime() {
if (time > 0) {
time--;
gel("timespan").innerHTML = time;
} else {
//清除時針
clearInterval(id);
}
}
window.onload = function() {
id = setInterval(dectime, 1000);
};
</script>
</head>
<body>
<span >倒計時<span id="timespan" style="color: red;"></span>秒</span>
</body>
</html>
js檢查輸入是否為數字.html
復制代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>js檢查輸入是否為數字</title>
<script type="text/javascript">
window.onload= function() {
document.getElementById("btn1").onclick = function() {
var i = prompt("輸入要判斷的值");
//window.alert(i);
if (!isNaN(i)) {
window.alert("是數字");
} else {
window.alert("不是數字");
}
};
}
</script>
</head>
<body>
<input type="button" id="btn1" value="判斷數字" />
</body>
</html>
js動態獲取、創建和刪除節點.html
復制代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js動態獲取、創建和刪除節點</title>
<script type="text/javascript">
function gel(id) { return document.getElementById(id); }
window.onload = function () {
gel("btnProAdd").onclick = function () {
//在proList下面增加子節點
var linew = document.createElement("li");
linew.innerHTML = prompt("輸入要新增的省份");
gel("proList").appendChild(linew);
//重新綁定所有的點擊刪除事件
DelLiOnClick();
};
//雙擊li子節點,刪除它
function DelLiOnClick() {
//1.首先得到所有的子節點
var liNodes = gel("proList").childNodes;
for (var i = 0; i < liNodes.length; i++) {
liNodes[i].onclick = function () {
//alert(liNodes[i]).innerHTML;//因為onclick綁定的是匿名函數,所以i到這裡永遠只會是7
//下面是正確的刪除方法, 使用this.因為觸發onclick事件的永遠是你選中的li
this.parentNode.removeChild(this);
};
}
}
};
</script>
</head>
<body>
<ul id="proList">
<li>山西</li>
<li>河南</li>
<li>北京</li>
</ul>
<input type="button" value="新增省份" id="btnProAdd" />
</body>
</html>
js中setInterval和setTimeout的使用.html
復制代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>js中setInterval和setTimeout的使用</title>
<script type="text/javascript">
var time = 10;
var id = 0;
function gel(id) {
return document.getElementById(id);
}
function dectime() {
if (time > 0) {
time--;
gel("timespan").innerHTML = time;
} else {
//清除時針
clearInterval(id);
}
}
window.onload = function() {
id = setInterval(dectime, 1000);
};
</script>
</head>
<body>
<span >倒計時<span id="timespan" style="color: red;"></span>秒</span>
</body>
</html>
js動態添加表格數據.html
復制代碼 代碼如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>動態添加表格數據</title>
<script type="text/javascript">
var mailArr = [
{ "title": "一個c#問題", "name": "張三", "date": "2014-03-21" },
{ "title": "一個javascript問題", "name": "李四", "date": "2014-03-21" },
{ "title": "一個c問題", "name": "五五", "date": "2014-03-21" },
{ "title": "一個c++問題", "name": "趙六", "date": "2014-03-21" }
];
window.onload = function () {
var tab = document.getElementById("tb");
//把mailArr循環遍歷方式以tr的方式加入表格中
for (var rowindex = 0; rowindex < mailArr.length; rowindex++) {
var tr = document.createElement("tr");
var th1 = document.createElement("th");
var th2 = document.createElement("th");
var th3 = document.createElement("th");
var th4 = document.createElement("th");
th1.innerHTML = "<input type='checkbox'/>";
th2.innerHTML = mailArr[rowindex].title;
th3.innerHTML = mailArr[rowindex].name;
th4.innerHTML = mailArr[rowindex].date;
tr.appendChild(th1);
tr.appendChild(th2);
tr.appendChild(th3);
tr.appendChild(th4);
tab.appendChild(tr);
}
};
</script>
</head>
<body>
<table id="tb" border="1px;" style="border-collapse: collapse;">
<tr>
<th>序列</th>
<th>標題</th>
<th>發郵人</th>
<th>發件時間</th>
</tr>
<!-- 循環增加 -->
</table>
</body>
</html>