JS操作HTML自定義屬性的方法
更新時間:2015年02月10日 16:54:44 作者:追求無限
這篇文章主要介紹了JS操作HTML自定義屬性的方法,以實例形式分析了html中自定義屬性的設(shè)置與對應(yīng)的javascript操作技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了JS操作HTML自定義屬性的方法。分享給大家供大家參考。具體如下:
HTML代碼如下(其中的displayName為自定義屬性):
復(fù)制代碼 代碼如下:
<input type="text" id="txtBox" displayName="123456" />
獲取自定義屬性值:
復(fù)制代碼 代碼如下:
document.getElementById("txtBox").getAttribute("displayName");
document.getElementById("txtInput").attributes["displayName"].nodeValue
document.getElementById("txtInput").attributes["displayName"].nodeValue
設(shè)置自定義屬性值:
復(fù)制代碼 代碼如下:
document.all.txtBox.setAttribute("displayName ","123456");
document.getElementById("txtInput").attributes["displayName"].nodeValue = "123456"
document.getElementById("txtInput").attributes["displayName"].nodeValue = "123456"
希望本文所述對大家的javascript程序設(shè)計有所幫助。
相關(guān)文章
JavaScript精煉之構(gòu)造函數(shù) Constructor及Constructor屬性詳解
對象的constructor屬性用于返回創(chuàng)建該對象的函數(shù),也就是我們常說的構(gòu)造函數(shù),除了創(chuàng)建對象,構(gòu)造函數(shù)(constructor) 還做了另一件有用的事情—自動為創(chuàng)建的新對象設(shè)置了原型對象(prototype object)2015-11-11基于Bootstrap table組件實現(xiàn)多層表頭的實例代碼
Bootstrap table還有一個很多強大的功能,下面就通過本文給大家分享基于Bootstrap table組件實現(xiàn)多層表頭的實例代碼,需要的朋友參考下吧2017-09-09