<div>good</div>
1、首先获取元素:var divObj = document.getElementByTag("div")[0]
2、设置id属性:divObj.setAttribute("id","divId")
或者divObj.id='divId'
var ele = document.getElementById('id_name')ele.id = 'id_name'
ele.setAttribute('name', 'name_value')
<div>good</div>
1、首先获取元素:var divObj = document.getElementByTag("div")[0]
2、设置id属性:divObj.setAttribute("id","divId")
或者divObj.id='divId'
var ele = document.getElementById('id_name')ele.id = 'id_name'
ele.setAttribute('name', 'name_value')