<button id = "id" type="button" name="a">你好,我是宝宝</button>
<script>
var att = document.getElementsByName("a");
att.setAttribute("class","one");
</script>
<style>
.one{
color: red;
}
<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;
}