问答详情
源自:9-6 setAttribute()方法

显示这行代码出错了?att.setAttribute("class","one");

<button  id = "id" type="button" name="a">你好,我是宝宝</button>

<script>

    var att = document.getElementsByName("a");

    att.setAttribute("class","one");

</script>

<style>

    .one{

        color: red;

    }


提问者:慕仔8415870 2021-07-23 22:17

个回答

  • weixin_慕数据5366478
    2021-07-26 09:21:45

    <button  id = "id" type="button" name="a" onclick="fun1">你好,我是宝宝</button>

    <script>

        function fun1(){

            var att = document.getElementsByName("a");

            att.setAttribute("class","one");

        }

    </script>

    <style>

        .one{

            color: red;

        }