Javascript得到HTML自定义属性

来源:互联网 发布:中国工业企业数据 编辑:程序博客网 时间:2024/05/16 10:17

<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="显示文本内容" onclick="showText();">

<input type="button" id="btnShowValue" name="btnShowValue" value="显示文本值" onclick="showValue();">

</body>

</html>

原创粉丝点击