源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

往光标所在位置插入值的js代码

  • 时间:2021-09-16 22:07 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:往光标所在位置插入值的js代码
[u]复制代码[/u] 代码如下:
<pre name="code" class="javascript">/** *往输入域中插入字符串(光标所在位置) *@param $t document.getElementById('fieldId') *@param myValue 要插入的值 ** function addSplitToField($t,myValue){ if (document.selection) { $t.focus(); sel = document.selection.createRange(); sel.text = myValue; $t.focus(); }else if($t.selectionStart || $t.selectionStart == '0') { var startPos = $t.selectionStart; var endPos = $t.selectionEnd; var scrollTop = $t.scrollTop; $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length); this.focus(); $t.selectionStart = startPos + myValue.length; $t.selectionEnd = startPos + myValue.length; $t.scrollTop = scrollTop; }else{ $t.value += myValue; $t.focus(); } } </pre><br><br>
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部