亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用javascript添加控件自定義屬性解析

 更新時(shí)間:2013年11月25日 09:23:52   作者:  
這篇文章主要是對(duì)用javascript添加控件自定義屬性進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助

前面說過為HTML元素添加自定義的屬性,是通過手動(dòng)在HTML控件中加上,其實(shí)可以在javascript中動(dòng)態(tài)添加:如有一文本框:

復(fù)制代碼 代碼如下:

<input type="text" id="txtInput" name="txtInput" value="自定義文本">

如想增加idvalue屬性(值為”自定義值”),可以在javascript中這樣寫:
復(fù)制代碼 代碼如下:

var txt = document.getElementById("txtInput");
txt.setAttribute("idvalue","自定義值");

setAttribute中第一個(gè)參數(shù)是指明自定義屬性的名稱,第二個(gè)參數(shù)是初始值

代碼如下:

復(fù)制代碼 代碼如下:

<html>
<head>
    <title>用javascript添加控件自定義屬性</title>
    <script language="javascript">
        function addCustomAttribute()
        {
            var txt = document.getElementById("txtInput");
            txt.setAttribute("idvalue","自定義值");
        }

        function showIdValue()
        {
                var txt = document.getElementById("txtInput");
                alert(txt.attributes["idvalue"].nodeValue);
        }
    </script>
</head>
<body onload="addCustomAttribute();">
    <input type="text" id="txtInput" name="txtInput" value="自定義文本">
    <input type="button" value="顯示idValue" onclick="showIdValue();">
</body>
</html>

相關(guān)文章

最新評(píng)論