首页 > 语言 > JavaScript > 正文

JS getAttribute和setAttribute(取得和设置属性)的使用介绍

2024-05-06 15:48:58
字体:
来源:转载
供稿:网友
本篇文章是对JS中的getAttribute和setAttribute(取得和设置属性)的使用进行了详细的分析介绍,需要的朋友可以参考下

getAttribute:取得属性;
setAttribute:设置属性;

复制代码 代码如下:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Untitled Document</title>
        <script language="JavaScript">
            function change() {
                var input = document.getElementById("li1");
                alert(input.getAttribute("title"));
                input.setAttribute("title", "mgc");
                alert(input.getAttribute("title"));
            }
        </script>
    </head>
    <body>
        <ul>
            <li value="Change" />
    </body>
</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选