1.js编写的代码嵌入html/xhtml文档才能执行,有两种方法:
1>在html 中 加入<script><script>
2>导入js 文件
2.javascrip 是弱类型语言,可以随意改变某个变量的数据类型
3.getElementsById() 根据ID查找DOM元素
getElementsByTagName("li") 得到一个对象数组
4.window.onlond = function 加载时调用
5.childNodes 获取该节点的子节点
6.元素节点的nodeType属性值是1
属性节点的nodeType属性值是2
文本节点的nodeType属性值是3
7.window.open(url,name,features) 打开新窗口
8.创造的 insertAfter 方法
function insertAfter(newElement,targetElement){
var parent = targetElement.parentNode;
if(parent.lastChild == targetElement){
parent.appendChild(newElement);
}else{
parent.insertBefore(newElement,targetElement,nextSibling);
}
}
9.document.createElement() 创建节点
10.appendChild 添加子节点
11.显示文件来源连接:
function displayCitations(){
if(!document.getElementByTagName||!document.createElement||!document.createTextNode) return false;
var quotes = document.getElementByTagName("blockquote");
for(var i =0;i<quotes.length;i++){
if(!quotes[i].getAttribute("cite")) continue;
var url = quote[i].getAttribute("cite");
var quoteChildren = quotes[i].getElementsByTagName('*');
if(quoteChildren,length<1) continue;
var elem = quoteChildren[quoteChildren.length-1];
var link = document.createElement("a");
var link_text = document.createTextNode("source");
link.appendChild(link_text);
link.setAttribute("href",url);
var superscript = document.createElement("sup");
superscript.appendChild(link);
elem.appdChild(supperscript);
}
}
12.1>为同一类型元素统一地声明一种样式
p {
font-size:1em;
}
2>为有着特定class属性的所有元素统一声明一种样式
.fineprint{
font-size:.8em;
}
3>为某个有着独一无二的ID属性的元素单独声明一种样式
#intro{
font-size:1.2em;
}
13.setTimeout("function",interval/时间/)
var movement = setTimeout("moveMessage()",5000);
clearTimeout(movement);取消
14.overflow的属性有4种:visible,hidden,scrpll,auto:
visible:不剪裁溢出内容,,浏览器讲溢出的内容呈现在其容器元素的显示区域以外的地方,全部内容在浏览器窗口都是可见的。
hidden:剪裁溢出的内容,内容只显示在其容器元素的显示区域内,这意味着只有一部分内容在浏览器窗口是可见的。
scroll :类似于hidden,浏览器将对溢出的内容进行剪裁,但是会显示滚动条以便让用户能够看到内容的其他部分。
auto:类似于scroll,当浏览器只有真的发生内容溢出时菜显示滚动条,如果内容没有溢出,就不显示滚动条