-
substr(提取的开始位置,提取的字符长度)
substring [提取的开始位置,提取的结束位置-1)
查看全部 -
注意每个case后,一定要加:break;
default,就相当于else查看全部 -
var mystr="Hello World!"
document.write(mystr.indexOf("v",8));
从下标为9开始寻找字符串"v"(下标从开始从0)
找不到则返回-1
查看全部 -
有点丑,仅供参考
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk2312"/>
<script type="text/javascript">
window.onload = function(){
changeColor();
}
function changeColor(){
var trs=document.getElementsByTagName("tr");
var len=trs.length;
var i;
for(i=0;i<len;i++){
trs[i].setAttribute("onmouseover","Color1(this)");
trs[i].setAttribute("onmouseout","Color2(this)");
}
}
function Color1(n){
n.style.backgroundColor="#f2f2f2";
}
function Color2(n){
n.style.backgroundColor="#fff";
}
function addNode(){
var newNode=document.createElement("tr");
var td_id=document.createElement("td");
var id=document.createElement("input");
id.type="text";
td_id.appendChild(id);
newNode.appendChild(td_id);
var td_name=document.createElement("td");
var name=document.createElement("input");
name.type="text";
td_name.appendChild(name);
newNode.appendChild(td_name);
var td_opt=document.createElement("td");
var del=document.createElement("a");
del.innerHTML="删除";
del.setAttribute("href","javascript:;");
del.setAttribute("onclick","delNode(this)");
td_opt.appendChild(del);
newNode.appendChild(td_opt);
document.getElementById("table").appendChild(newNode);
changeColor();
}
function delNode(n){
n.parentNode.parentNode.parentNode.removeChild(n.parentNode.parentNode);
}
</script>
</head>
<body>
<table border="1" width="50%" id="table">
<tr>
<th>学号</th>
<th>姓名</th>
<th>操作</th>
</tr>
<tr>
<td>xh001</td>
<td>王小明</td>
<td><a href="javascript:;" onclick="delNode(this)" >删除</a></td> <!--在删除按钮上添加点击事件 -->
</tr>
<tr>
<td>xh002</td>
<td>刘小芳</td>
<td><a href="javascript:;" onclick="delNode(this)" >删除</a></td> <!--在删除按钮上添加点击事件 -->
</tr>
</table>
<input type="button" value="添加一行" onclick="addNode()" /> <!--在添加按钮上添加点击事件 -->
</body>
</html>查看全部 -
需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var w = document.documentElement.scrollWidth || document.body.scrollWidth;
var h = document.documentElement.scrollHeight || document.body.scrollHeight;
document.write(w," ",h);
</script>
</body>
</html>查看全部 -
需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var w=document.documentElement.cilentWidth||document.body.clientWidth;
var h=document.documentElement.clientHeight||document.body.client.Height;
document.write(w," ",h)
</script>
</body>
</html>查看全部 -
需要的同学可以参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
.message{
width:200px;
height:100px;
background-color:#CCC;}
</style>
</head>
<body>
<script type="text/javascript">
var p=document.createElement("p");
p.className="pTag";
var pText=document.createTextNode("I love JavaScript");
p.appendChild(pText);
document.body.appendChild(p);
</script>
</body>
</html>查看全部 -
需要的同学可以参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<script type="text/javascript">
var main = document.body;
function createa(url,text)
{
var body=document.body;
var href=document.createElement("a");
href.href=url;
href.text=text;
body.appendChild(href);
}
createa("http://www.imooc.com","慕课网");
</script>
</body>
</html>查看全部 -
<div id="text"> <p id="con"> parentNode 获取指点节点的父节点</p> </div> <script type="text/javascript"> var mynode= document.getElementById("con"); document.write(mynode.parentNode.nodeName); </script>
查看全部 -
有需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<div><b id="oldnode">JavaScript</b>是一个很常用的技术,为网页添加动态效果。</div>
<a href="javascript:replaceMessage()"> 将加粗改为斜体</a>
<script type="text/javascript">
function replaceMessage(){
var newnode=document.createElement("i");
newnode.innerHTML="replaceNode";
var oldnode=document.getElementById("oldnode");
oldnode.parentNode.replaceChild(newnode,oldnode);
}
replaceMessage();
</script>
</body>
</html>查看全部 -
需要的同学可以参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="content">
<h1>html</h1>
<h1>php</h1>
<h1>javascript</h1>
<h1>jquery</h1>
<h1>java</h1>
</div>
<script type="text/javascript">
function clearText() {
var content=document.getElementById("content");
var len=content.childNodes.length;
document.write(len+"<br/>");
for(i=0;i<len;i++){
content.removeChild(content.childNodes[i]);
document.write(content.childNodes[i].nodeValue+"<br/>");
}
}
</script>
<button onclick="clearText()">清除节点内容</button>
</body>
</html>查看全部 -
需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<ul id="test"><li>JavaScript</li><li id="x1">HTML</li></ul>
<script type="text/javascript">
var otest = document.getElementById("test");
var node=document.getElementById("x1");
var php=document.createElement("li");
php.innerHTML="php";
otest.insertBefore(php,node);
</script>
</body>
</html>查看全部 -
需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>nextSibling</title>
</head>
<body>
<ul id="u1">
<li id="a">javascript</li>
<li id="b">jquery</li>
<li id="c">html</li>
</ul>
<ul id="u2">
<li id="d">css3</li>
<li id="e">php</li>
<li id="f">java</li>
</ul>
<script type="text/javascript">
function get_nextSibling(n){
var x=n.nextSibling;
while (x && x.nodeType!=1){
x=x.nextSibling;
}
return x;
}
function get_previousSibling(n){
var x=n.previousSibling;
while(x&&x.nodeType!=1){
x=x.previousSibling
}
return x;
}
var x=document.getElementsByTagName("li")[0];
document.write(x.nodeName);
document.write(" = ");
document.write(x.innerHTML);
var y=get_nextSibling(x);
if(y!=null){
document.write("<br />nextsibling: ");
document.write(y.nodeName);
document.write(" = ");
document.write(y.innerHTML);
}else{
document.write("<br>已经是最后一个节点");
}
var z=get_previousSibling(x);
if(z!=null){
document.write("<br />previoussibling: ");
document.write(z.nodeName);
document.write(" = ");
document.write(z.innerHTML);
}else{
document.write("<br>已经是第一个节点");
}
</script>
</body>
</html>查看全部 -
需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<ul id="con">
<li id="lesson1">javascript
<ul>
<li id="tcon"> 基础语法</li>
<li>流程控制语句</li>
<li>函数</li>
<li>事件</li>
<li>DOM</li>
</ul>
</li>
<li id="lesson2">das</li>
<li id="lesson3">dadf</li>
<li id="lesson4">HTML/CSS
<ul>
<li>文字</li>
<li>段落</li>
<li>表单</li>
<li>表格</li>
</ul>
</li></ul>
<script type="text/javascript">
var mylist = document.getElementById("tcon");
document.write(mylist.parentNode.parentNode.parentNode.childNodes[7].childNodes[0].nodeValue);
</script>
</body>
</html>查看全部 -
需要的同学可参考
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="con">
<p>javascript</p>
<div>jQuery</div>
<h5>PHP</h5>
</div>
<script type="text/javascript">
var x=document.getElementById("con");
document.write(x.firstChild+"<br/>");
document.write(x.lastChild);
</script>
</body>
</html>查看全部
举报