javascriptよくある使い方のまとめ
6952 ワード
jsデコードとコード.html
javascript
<br>
<br>function gel(id) {
<br>return document.getElementById(id);
<br>}
<br>
<br>window.onload = function() {
<br>//alert(document.getElementById("span1").innerHTML
<br>gel("btn1").onclick = function() {
<br>alert(encodeURI(gel("span1").innerHTML));
<br>};
<br>
<br>gel("btn2").onclick = function() {
<br>alert(decodeURI(gel("span1").innerHTML));
<br>};
<br>};
<br>
!
js中setIntervalとsetTimeoutの使用.html
js setInterval setTimeout
<br>var time = 10;
<br>var id = 0;
<br>function gel(id) {
<br>return document.getElementById(id);
<br>}
<br>
<br>function dectime() {
<br>if (time > 0) {
<br>time--;
<br>gel("timespan").innerHTML = time;
<br>} else {
<br>//
<br>clearInterval(id);
<br>}
<br>}
<br>
<br>window.onload = function() {
<br>id = setInterval(dectime, 1000);
<br>};
<br>
jsは入力が数字かどうかを検査します.)
js
<br>
<br>
<br>
<br>window.onload= function() {
<br>document.getElementById("btn1").onclick = function() {
<br>var i = prompt(" ");
<br>//window.alert(i);
<br>if (!isNaN(i)) {
<br>window.alert(" ");
<br>} else {
<br>window.alert(" ");
<br>}
<br>};
<br>}
<br>
jsダイナミックにノードを取得、作成、削除します.
js 、
<br>function gel(id) { return document.getElementById(id); }
<br>
<br>window.onload = function () {
<br>gel("btnProAdd").onclick = function () {
<br>// proList
<br>var linew = document.createElement("li");
<br>linew.innerHTML = prompt(" ");
<br>gel("proList").appendChild(linew);
<br>//
<br>DelLiOnClick();
<br>};
<br>
<br>// li ,
<br>
<br>function DelLiOnClick() {
<br>//1.
<br>var liNodes = gel("proList").childNodes;
<br>
<br>for (var i = 0; i < liNodes.length; i++) {
<br>liNodes[i].onclick = function () {
<br>//alert(liNodes[i]).innerHTML;// onclick , i 7
<br>// , this. onclick li
<br>this.parentNode.removeChild(this);
<br>};
<br>}
<br>}
<br>
<br>
<br>};
<br>
-
-
-
js中setIntervalとsetTimeoutの使用.html
js setInterval setTimeout
<br>var time = 10;
<br>var id = 0;
<br>function gel(id) {
<br>return document.getElementById(id);
<br>}
<br>
<br>function dectime() {
<br>if (time > 0) {
<br>time--;
<br>gel("timespan").innerHTML = time;
<br>} else {
<br>//
<br>clearInterval(id);
<br>}
<br>}
<br>
<br>window.onload = function() {
<br>id = setInterval(dectime, 1000);
<br>};
<br>
jsダイナミックにテーブルデータを追加します.html
<br>
<br>var mailArr = [
<br>{ "title": " c# ", "name": " ", "date": "2014-03-21" },
<br>{ "title": " javascript ", "name": " ", "date": "2014-03-21" },
<br>{ "title": " c ", "name": " ", "date": "2014-03-21" },
<br>{ "title": " c++ ", "name": " ", "date": "2014-03-21" }
<br>];
<br>
<br>window.onload = function () {
<br>var tab = document.getElementById("tb");
<br>// mailArr tr
<br>for (var rowindex = 0; rowindex < mailArr.length; rowindex++) {
<br>var tr = document.createElement("tr");
<br>var th1 = document.createElement("th");
<br>var th2 = document.createElement("th");
<br>var th3 = document.createElement("th");
<br>var th4 = document.createElement("th");
<br>th1.innerHTML = "<input type='checkbox'/>";
<br>th2.innerHTML = mailArr[rowindex].title;
<br>th3.innerHTML = mailArr[rowindex].name;
<br>th4.innerHTML = mailArr[rowindex].date;
<br>
<br>tr.appendChild(th1);
<br>tr.appendChild(th2);
<br>tr.appendChild(th3);
<br>tr.appendChild(th4);
<br>
<br>tab.appendChild(tr);
<br>}
<br>
<br>};
<br>