Javascript获得对象、属性常用语句
1.获得指定id的对象:document.getElementById ("id"),id需唯一,name不必唯一。
2.获得指定name的对象数组:document.getElementsByname("name"),访问具体对象用下标表示:document.getElementsByname("name")[0]
3. 获得触发事件的对象:
function getEventElement(ev){
ev = ev||window.event;//获得对象
var target = ev.target || ev.srcElement;
var id = target.getAttribute("id");//获得该对象的id属性
}
4.获得table的某一行、某一列:
function setTdColor(){//设置表格颜色
var table = document.getElementById("myTable");//页面中存在id为myTable的table
for (var i = 0;i<table.rows.length;i++){//rows为table的所有行对象数组
table.rows[i].cells[0].bgColor = "FFFFFF";//cells为一行所有列的数组
}
}
相关文档:
scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......
javascript中innerHtml用法
2009-04-21 22:52
<html>
<head>
<script language="javascript">
function Test(){
var str="";
str+="Hello,";
str+="This ......
源码:
function resize(img, width, height) {
(img.width > img.height)
? ((img.height = Math.min(height, width * img.height/img.width)) || (img.width = Math.min(width, img.width)))
: ((img.width = Math.min(width, height * img.width/img.height)) || (img.height = Math.min(hei ......
function
clone(jsonObj) {
var
buf;
if
(jsonObj
instanceof
Array) {
buf = [];
......