日期:2014-05-16 浏览次数:20358 次
<script type='text/javascript'> window.onload = function(){ var html = '<span style="background:yellow" class="myspan">bbbbb</span>'; document.getElementById('l').onclick = function(){ /*IE*/ range = document.selection.createRange(); range.pasteHTML(html); var pElem = range.parentElement(); chElems = pElem.getElementsByTagName('span'); for(var i = 0, len = chElems.length; i < len; ++i){ if(chElems[i].className === 'myspan'){ break; } } var brange = document.body.createTextRange(); brange.moveToElementText(chElems[i]); brange.select(); }; }; </script> <html> <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p> <input type='button' id = 'l' value='insert' /> </html>