JS 對文本框指定焦點差入值
參考文章:http://www.111cn.net/wy/js-ajax/52270.htm
這種方法可行。
通過上面的我們就可以將DIV中的光標移動到最後面了
一個完整的實例
代碼如下 | 復制代碼 |
<button type=”button” onclick=”document.getElementById(‘test’).focus(); insertHtmlAtCaret(‘<b>INSERTED</b>’);”>插入字符</button>
function insertHtmlAtCaret(html) { // Range.createContextualFragment() would be useful here but is el.innerHTML = html; var frag = document.createDocumentFragment(), node, lastNode; while ( (node = el.firstChild) ) { lastNode = frag.appendChild(node); } range.insertNode(frag); // Preserve the selection sel.removeAllRanges(); sel.addRange(range); } } } else if (document.selection && document.selection.type != “Control”) { // IE < 9 document.selection.createRange().pasteHTML(html); } } |
本文出自 “JianBo” 博客,轉載請與作者聯系!
JS 對文本框指定焦點差入值