Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以使用原型/javascript 将 id 插入到 div 中?基本上:
<div> Hello </div>
应该变成:
<div id="myId"> Hello </div>
谢谢!
是的,但是如果没有更多代码,这将很难做到,因为您无法识别<div>它当前的编码方式。如果它跟随一个<div>with 和 IDsomediv那么你可以这样做:
<div>
somediv
$$('#somediv > div')[0].setAttribute('id', 'myId');
$("somelement").writeAttribute("id","myid");