windows.document對象

來源:互聯網
上載者:User

標籤:

1.1找元素

document.getElementById("id");根據id找最多找一個;

var a=document.getElementById("id");將找到的元素放在變數中;

document.getElementByNames("name");根據name找,找出來的是數組;

document.getElementByTagNames("name");根據表簽名找,找出來的是數組;

document.getElementByClassNames("name");根據表classname找,找出來的是數組;

alert(a.innerHTML);標籤裡的html代碼和文字都擷取了

alert(a.innerText);只擷取裡面的文字;

alert(a.outHTML);包括標籤本身的內容;

 

1.2操作元素

var a=var a=document.getElementById("id");

a.setAttribute("屬性名稱","屬性值");設定一個屬性,添加或更改都可以;

a.getAttribute("屬性名稱");擷取屬性值;

a.removeAttribute("屬性名稱");移除一個屬性

樣本:展示圖片的自動和手動切換,並插入超連結。

代碼:

<style>

#zlunbo
{ background-image:url(zk2.png) ; width:830px; height:540px; position:relative; margin-left:250px;}
#zzuo
{
width: 33px;
height: 124px;
position: absolute;
left: -30px;
top: 214px;
line-height: 124px;
font-size: 50px;
}
#zzuo:hover
{ background-color:#C7C7C7; opacity:60%;
}
#zyou
{
width: 33px;
height: 124px;
position: absolute;
left: 831px;
top: 214px;
line-height: 124px;
font-size: 50px;
}
#zyou:hover
{ background-color:#C7C7C7; opacity:60%;
}

</style>

<body>

<div id="zlunbo"><a target="new" id="zll"><div style=" height:540px;"></div></a>
<div id="zzuo" onclick="dodo(-1)"> < </div>
<div id="zyou" onclick="dodo(1)"> > </div>
</div>

</body>

<script>

var jpg=new Array();
jpg[0]="url(zk2.png)";
jpg[1]="url(zt1.png)";
jpg[2]="url(zx1.png)";
var xb =0;var n=0;var lbimg=document.getElementById("zlunbo")
function huan()
{xb++;
if(xb==3)
{xb=0}
lbimg.style.backgroundImage=jpg[xb];
if(n==0)
{window.setTimeout("huan()",4000);}
var zll1=document.getElementById("zll").href
var zllianjie=new Array();
zllianjie[0]="http://www.baidu.com"
zllianjie[1]="http://www.360.com"
zllianjie[2]="http://www.qq.com"
document.getElementById("zll").href=zllianjie[xb]

}
function dodo(m)
{n=1;
xb=xb+m;
if(xb<0)
{xb=2;}
else if(xb>=3)
{xb=0;}
lbimg.style.backgroundImage=jpg[xb];
var zll1=document.getElementById("zll").href
var zllianjie=new Array();
zllianjie[0]="http://www.baidu.com"
zllianjie[1]="http://www.360.com"
zllianjie[2]="http://www.qq.com"
document.getElementById("zll").href=zllianjie[xb]

}
window.setTimeout("huan()",4000);

</script>

windows.document對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.