JSON

非常全的jQuery常用技巧总结(8)

字号+ 作者:H5之家 来源:H5之家 2016-05-20 14:04 我要评论( )

jQuery.fn.extend({ set_caret: function(){ if(!$.browser.msie) return; var initSetCaret = function(){this.caretPos = document.selection.createRange().duplicate()}; this.click(initSetCaret).select(init


jQuery.fn.extend({
    set_caret: function(){
        if(!$.browser.msie) return;
        var initSetCaret = function(){this.caretPos = document.selection.createRange().duplicate()};
        this.click(initSetCaret).select(initSetCaret).keyup(initSetCaret);
    }, 
    insert_caret:function(textFeildValue){
        var textObj = this[0];
        if(document.all && textObj.createTextRange && textObj.caretPos){
            var caretPos=textObj.caretPos;
            caretPos.text = caretPos.text.charAt(caretPos.text.length-1) == '' ? textFeildValue+'' : textFeildValue;
        } else if(textObj.setSelectionRange){
            var rangeStart=textObj.selectionStart;
            var rangeEnd=textObj.selectionEnd;
            var tempStr1=textObj.value.substring(0,rangeStart);
            var tempStr2=textObj.value.substring(rangeEnd);
            textObj.value=tempStr1+textFeildValue+tempStr2;
            textObj.focus();
            var len=textFeildValue.length;
            textObj.setSelectionRange(rangeStart+len,rangeStart+len);
            textObj.blur();
        } else {
            textObj.value+=textFeildValue;
        }
    }
})

前台要用就比较简单了,  只需要这样写:
<div>
                <h3>
                    这里可以放标题
                h3>
                <div>
                    这里是一些主要的内容
                    <dl>
                        <dt>Hello worlddt>
                        <dd>
                            hahahadd>
                    dl>
                    这个实验在沙加的神舟本上完成
                div>
                <div>
                    <a href="javascript:void(0);">[收起]a> <a
                        href="javascript:void(0);">[展开]a>
                div>
            div>

样式就省略了, 大家可以自己写, 最后发两个效果图:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 如何获取JQUERY AJAX返回的JSON结果集实现代码

    如何获取JQUERY AJAX返回的JSON结果集实现代码

    2016-05-14 14:05

  • 如何解决JQuery ajaxSubmit提交中文乱码

    如何解决JQuery ajaxSubmit提交中文乱码

    2016-05-14 11:01

  • jQuery通过Ajax返回JSON数据

    jQuery通过Ajax返回JSON数据

    2016-05-04 16:00

  • jQuery基于json与cookie实现购物车的方法

    jQuery基于json与cookie实现购物车的方法

    2016-04-24 11:00

网友点评