js獲取和設置屬性

function square(num){
?? ?var total = num*num;//局部變量
?? ?return total;
}
var total = 50;//全局變量
var number = square(20);
alert(total);//結果為50

function square(num){
?? ?total = num*num;//全局變量
?? ?return total;
}
var total = 50;//全局變量
var number = square(20);
alert(total);//結果為400
這細微的差別就會影響到程序的結果

body{
?? ?color:white;
?? ?background-color:black;
}
這些顏色不僅作用于那些直接包含在<body>標簽里的內容,還將作用于嵌套在body元素內的所有元素

id屬性就像一個掛鉤,它一頭連著文檔里的某個元素,另一頭連著CSS樣式表里的某個樣式

document.getElementById("purchases")這個調用將返回一個對象,這個對象對應著document對象里的一個獨一無二的元素,那個元素
的的id屬性值為purchases

其實,文檔中的每個元素都是一個對象。利用DOM提供的方法能夠得到任何一個對象。

getElementsByTagName返回一個數組,即使整個文檔里只有一個元素,也返回一個數組。
示例:
var items = document.getElementsByTagName("li");
for(var i = 0;i<items.length;i++){
?? ?alert(typeof items[i]);
}
顯示信息都是object

?getElementByClassName
也返回一個具有相同類名的元素數組

?獲取和設置屬性
?getAttribute
object.getAttribute(attribute)
注:getAttribute方法不屬于document對象,它只能通過元素節點對象調用。
?setAttribute
object.setAttribute(attribute,value)
例子:
var shopping = document.getElementById("purchases");
shopping.setAttribute("title","a list of goods");

轉載于:https://www.cnblogs.com/jiqing9006/archive/2013/03/01/2938394.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274344.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274344.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274344.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

hp-ux鎖定用戶密碼_我們如何簡化925移動應用程序的用戶入門— UX案例研究

hp-ux鎖定用戶密碼Prologue: While this is fundamentally a showcase of our process in the hopes of helping others, it’s also a story about the realism of limitations when working with clients and how we ultimately were able to deliver a product the client w…

微信公眾號無需二次登錄_您無需兩次解決問題-您需要一個設計系統

微信公眾號無需二次登錄重點 (Top highlight)The design system concept can be differently defined according to each person’s background. Designers may say that a design system is a style guide while developers may say it is UI standards, or specs, or even as…

android中AsyncTask和Handler對比

1 &#xff09; AsyncTask實現的原理,和適用的優缺點 AsyncTask,是android提供的輕量級的異步類,可以直接繼承AsyncTask,在類中實現異步操作,并提供接口反饋當前異步執行的程度(可以通過接口實現UI進度更新),最后反饋執行的結果給UI主線程. 使用的優點: l 簡單,快捷 l 過程可…

視覺工程師面試指南_選擇正確視覺效果的終極指南

視覺工程師面試指南When it comes to effective data visualization, the very first and also the most critical step is to select the right graph/visual for the data that you want to present. With a wide range of visualization software that is available offerin…

在 Linux 下使用 水星MW150cus (RTL8188CUS芯片)無線網卡

Fedora &#xff08;如果你不使用 PAE 內核&#xff0c;請去掉 PAE 字樣&#xff09;:yum install gcc kernel-PAE kernel-PAE-devel kernel-headers dkms Ubuntu: apt-get install make gcc linux-kernel-devel linux-headers-uname -r安裝原生驅動 注意&#xff1a;由于在 Li…

問題反饋模板_使用此模板可獲得更好,更有價值的UX反饋

問題反饋模板Feedback is an important part of UX design. To improve the work you do you need to be able to give and receive feedback. Receiving valuable feedback is for a very large part up to you.反饋是UX設計的重要組成部分。 為了改進您的工作&#xff0c;您需…

【轉載】Android Animation 簡介(官方文檔翻譯) ---- 翻譯的很好!

http://vaero.blog.51cto.com/4350852/849783轉載于:https://www.cnblogs.com/DonkeyTomy/articles/2945687.html

ubuntu 如何轉換 ppk ,連接 amazon ec2

轉 自 &#xff1a;http://www.ehow.com/how_8658327_convert-ppk-ssh-ubuntu.html1 Open a terminal window in Ubuntu, or log in if you are converting the keys on a remote Ubuntu server. 2 Type "sudo apt-get install putty-tools" at the terminal prompt …

iofd:文件描述符_文字很重要:談論設計時18個有意義的描述符

iofd:文件描述符As designers, many of us think we’re just visual creatures. But creating visuals is only half of the job. The other half is verbal communication — actually talking about design. Whether we’re showcasing our own work, giving or receiving c…

保護程序猿滴眼睛-----修改VS 2008 編輯器顏色 (修改 chrome瀏覽器的背景色)

前幾天更改了 chrome 的背景色后&#xff0c;雖然有些地方看起來不和諧&#xff0c;想百度的首頁&#xff0c;顯示出了大快的圖片區域&#xff0c;但是&#xff0c;整體感覺這個顏色設置真的對眼睛有一定保護作用。。。 所以&#xff0c;再順便修改一下 經常用的 vs2008 編輯器…

數據可視化 信息可視化_可視化哲學的黎明

數據可視化 信息可視化Note: this is the foreword of the book Data Visualization in Society (Amsterdam University Press, 2020)注意&#xff1a;這是《 社會中的數據可視化 》一書的前言 (阿姆斯特丹大學出版社&#xff0c;2020年) Geographer John Pickles once wrote …

HTTP 錯誤 404.2 - Not Found 由于 Web 服務器上的“ISAPI 和 CGI 限制”列表設置,無法提供您請求的頁面...

詳細錯誤&#xff1a;HTTP 錯誤 404.2 - Not Found. 由于 Web 服務器上的“ISAPI 和 CGI 限制”列表設置&#xff0c;無法提供您請求的頁面. 出現環境&#xff1a;win7 IIS7.0 解決辦法&#xff1a;IIS的根節點->右側“ISAPI和CGI限制”->把禁止的DotNet版本項設置為允許…

重口味動漫_每種口味的圖標樣式

重口味動漫The icons are, without a doubt, one of the most used graphic elements today in the interface design of digital products. And to make this statement with some degree of certainty, we do not even need a very robust statistical analysis. Just rememb…

JSP入門

一、什么是JSP&#xff1f; JSP&#xff08;Java Server Pages)是由Sun Microsystems公司倡導、許多公司參與一起建立的一種動態網頁技術標準。JSP技術有點類似ASP技術&#xff0c;它是在傳統的網頁HTML文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP標記(tag)&#xff0…

初學c++

看了兩章不到。。隨意記錄下。 #include<iostream> #include<string> using std::cout; using std::endl; double calculation(double a,double b,char op) {switch(op){case : return ab;case -:return a-b;case *:return a*b;case /:return a/b;}}double num0;do…

從頭開始vue創建項目_我正在以設計師的身份開始一個被動的收入項目。 從頭開始。...

從頭開始vue創建項目Do you ever read an article on Medium (or elsewhere) about passive income, side projects and big money making blogs? When I read such an article it looks like it is easy to do yourself if you just put in the work. To see if that is the …

Exaple2_1(顯示轉換)

public class Example2_1{ public static void main(String arg[]){ char ca; System.out.println(""c"unicode:"(int)c); System.out.println(":"); for(int i(int)c;i<c25;i){ System.out.println(""(char)i); } }}轉載于…

英國文化影響管理風格_文化如何影響用戶體驗

英國文化影響管理風格重點 (Top highlight)The Internet makes the world a smaller place. You can make money or gain users outside of your demographic with a digital product or service easier than a physical business. But, is selling the exact same design of t…

ubuntu12.04安裝教程

第一部分&#xff1a;準備Ubuntu12.04的啟動盤 Ubuntu支持可移動盤和CDROM安裝&#xff0c;筆者選擇后者。在Ubuntu官網http://www.ubuntu.org.cn/download/desktop下載Ubuntu鏡像文件(.iso)&#xff0c;通過光盤刻錄機將該鏡像文件刻錄到一張空白CD/DVD上。 第二部分&#xff…

element ui 空格_空格是您的UI朋友。 大量使用它。

element ui 空格Originally published at marcandrew.me on July 30th, 2020.最初于 2020 年7月30日 在 marcandrew.me 上 發布 。 Ah good old White Space. One of the simplest things to add to your designs to improve both your UIs, and user experience. Let me shar…