它的用途并非僅限于處理網頁,也可以用來處理任何一種使用標記語言編寫出來 " /> 被男人吃奶很爽的毛片两男一女,热久久视久久精品18国产,久艹在线视频

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

jQuery DOM操作小結與實例

DOM操作的分類:DOM CORE(核心)、HTML-DOM和CSS-DOM
1. DOM Core
DOM Core并不專屬于Javascript,任何一種支持DOM的程序設計語言都可以使用它。

它的用途并非僅限于處理網頁,也可以用來處理任何一種使用標記語言編寫出來的文檔,如XML.

Javascript中的getElementById(),getElementByTagName(),getAttribute()和setAttribute()方法,都是dom core的組成部分。

2. HTML_DOM

使用HTML_DOM來獲取表單對象的方法
Document.forms
使用HTML_DOM來獲取某元素的src屬性的方法
Element.src
3. CSS_DOM

CSS_DOM是針對CSS的操作。在Javascript中,CSS-DOM技術的主要作用是獲取和設置style對象的各個屬性。通過改變style對象的各種屬性,可以使網頁呈現出各種不同的效果。
Element.style.color = “red”;
jQuery作為Javascript庫,繼承并發揚了Javascript對DOM對象的操作的特性,使開發人員能方便的操作DOM對象。

jQuery 的DOM操作方法 元素的創建、復制、重組、修飾。下面的例子完全可用,每一行都寫有注釋,請復制代碼運行。
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<title></title>
<script src="http://img.jb51.NET/jslib/jquery/jquery.js" type="text/Javascript"></script>
<style type="text/css">
.chapter
{
width: 42em;
}
a.link
{
text-decoration: none;
}
span.footnote
{
font-style: italic;
font-family: "Times New Roman" , Times, serif;
display: block; /*使其變成一塊一塊的*/
margin: 1em 0;
}
.text-reference
{
font-weight: bold;
}
#notes li
{
margin: 1em 0;
}
#notes
{
margin-top: 1em;
border-top: 1px solid #00ff00;
}
#footer
{
margin-top: 1em;
border-top: 1px solid #dedede; /*上邊線*/
}
.inhabitants
{
border-bottom: 1px solid #dedede;
}
.pulled-wrapper
{
background: url(pq-top.jpg) no-repeat left top;
position: absolute;
width: 160px;
right: -180px; /* 定位注釋框的橫向位置*/
padding-top: 18px;
}
.pulled
{
background: url(pq-bottom.jpg) no-repeat left bottom;
position: relative;
display: block;
width: 140px;
padding: 0 10px 24px 10px;
font: italic 1.4em "Times New Roman" , Times, serif;
}
</style>
<script type="text/Javascript">
//為每個p元素添加屬性
$(document).ready(function() {
$('p').each(function(index) {
var currentClass = $(this).attr('class');
$(this).attr('class', currentClass + ' inhabitants');
});
});

//動態為元素添加屬性
$(document).ready(function() {
$('div.chapter a[href*=cnblogs]').each(function(index) { //each好似for循環,他會循環集合中所有的對象,參數一的方法是對每一個對象都執行的操作,index是對象的索引
var $thisLink = $(this);
$(this).attr({
'rel': 'subsection ',
'id': 'blogslink-' + index,
'title': '更多' + $thisLink.text() + '的資料在馮瑞濤的博客',
'class': 'link'
});
});
});
//插入返回到上面連接
$(document).ready(function() {
$('<a id="top" name="top">新年好</a>').prependTo('body'); //初始化到body
$('div.chapter p:gt(0)').after('<a href="#top">返回到上面</a>');
//下行等價上面的哪行代碼 gt代表從第幾個元素后面的p開始
//$('<a href="#top">返回到上面</a>').insertAfter('div.chapter p:gt(0)');
});
//
$(document).ready(function() {
$('<ol id="notes"></ol>').insertAfter('div.chapter');
$('span.footnote').each(function(index) {
$(this)
//為每一個footnote在前面動態添加數字連接(1,2)
.before('<a href="#foot-note-' + (index + 1) + '" id="context-' + (index + 1) + '" class="context"><sup>' + (index + 1) + '</sup></a>')
//將footnote插入到ol標簽中(不帶上面的連接,僅span),就是移動標簽,帶有appendTo代表將自己追加到其他元素中
.appendTo('#notes')
// 向指定元素內容的后面追加標簽
.append(' (<a href="#context-' + (index + 1) + '">內容</a>)')
//將this包含在wrap的第一個參數中表示的標記中
.wrap('<li id="foot-note-' + (index + 1) + '"></li>');
});
});
$(document).ready(function() {
$('span.pull-quote').each(function(index) {
//獲得父元素p
var $parentParagraph = $(this).parent('p');
//設置p標簽為相對定位,否則無法對其位置進行操作
$parentParagraph.css('position', 'relative');
//復制一份拷貝,span.pull-quote clone(false);代表僅復制標記本身不復制其內容
var $clonedCopy = $(this).clone();
$clonedCopy
.addClass('pulled') //添加樣式,擁有下面的背景
.find('span.drop') //找到其中的span.drop,此時對象已經是span.drop了
.html('…') //為span.drop 設置html文檔
.end() //返回沒有被改變前的那個jQuery對象狀態
.prependTo($parentParagraph) //將這個span追加到指定的元素中去
.wrap('<div class="pulled-wrapper"></div>'); //再其本身包含在div內容中<div><span>
var clonedText = $clonedCopy.text(); //獲得文本,去掉了html
$clonedCopy.html(clonedText); //將文本以Html的形式插入到內容中,相當于替換html內容
});
});


</script>
</head>
<body>
<form id="form1">
<span class="footnote">佳月</span> <span class="footnote">Terry.Feng.C</span> <span
class="footnote">馮瑞濤</span>
<div class="chapter">
<p>
1. <a >jQuery</a>動態為鏈接添加屬性。</p>
<p>
2. <a >CSLA.NET</a>業務層最強框架。<span class="pull-quote">CSLA注釋<span class="drop">省略部分</span></span></p>
<p>
3. <a >DNN</a>免費開源的CMS系統。<span class="pull-quote">DNN注釋<span class="drop">省略部分</span></span></p>
</div>
<div id="footer">
馮瑞濤的博客</div>
</form>
</body>
</html>

JavaScript技術jQuery DOM操作小結與實例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 午夜视频免费观看黄 | 日韩美女性行为免费视频 | 免费激情| 国产精品免费久久久久影院小说 | 五月激情六月婷婷 | 99香蕉国产精品偷在线观看 | 久久久麻豆 | 久久国产精品伦理 | 久久这里一区二区精品 | 日本在线www| 国产一级做a爰片久久毛片 国产一级做a爰片久久毛片99 | 亚洲图片欧美在线 | 国产精品高清一区二区三区不卡 | 久久韩国精品韩国专区 | 韩国一级爽快片淫片高清 | 天天爱综合| 全部免费69堂在线视频 | 国产精品1024永久观看 | 涩涩涩综合在线亚洲第一 | 欧美日韩国产另类一区二区三区 | 激情影院a| 99久久综合狠狠综合久久 | 国产成人一区二区三区影院免费 | 五月亭亭免费高清在线 | 婷婷久操 | 激情在线播放免费视频高清 | 欧美特黄一片aa大片免费看 | 欧美xxxx三人交性视频 | 久久99精品国产99久久 | 亚洲国产高清精品线久久 | 欧美白人猛性xxxxx交69 | 色噜噜狠狠一区二区三区 | 成人午夜免费视频毛片 | 伊人久久综在合线亚洲91 | 国产桃色在线成免费视频 | 免费在线观看黄网站 | 亚洲天堂久久精品成人 | 激情小说图片 | 五月婷婷激情 | 国产福利小视频 | 成人午夜免费视频毛片 |