原生js
<script type="text/javascript"> var divHtml= ‘<div>‘+ ‘<ul>‘+ ‘<li>‘+ ‘<a href="#">something added</a>‘+ ‘</li>‘+ ‘</ul>‘+ ‘</div>‘; var div=document.createElement(‘div‘); div.innerHTML=divHtml; document.body.appendChild(div); var li=div.getElementsByTagName(‘li‘)[0]; console.log(li); </script>
jquery实现
时间: 2024-10-10 11:59:02