Javascript得到HTML自定義屬性

<html>

<head>

<title>自定義屬性</title>

<script language="javascript">

function showText()

{

alert(document.getElementById("txtInput").value);

}

function showValue()

{

alert(document.getElementById("txtInput").attributes["idvalue"].nodeValue);

}

</script>

</head>

<body>

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

<input type="button" id="btnShowText" name="btnShowText" value="顯示文本內容" οnclick="showText();">

<input type="button" id="btnShowValue" name="btnShowValue" value="顯示文本值" οnclick="showValue();">

</body>

</html>

發佈了74 篇原創文章 · 獲贊 3 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章