Js:
/*******************************************
*
* Plug-in at the insertion cursor
* @authors Du Xin Li
* @update 2015-10-25
*
*********************************************/
$.fn.extend ({
Insertcontent:function (myvalue, t) {
var = $ (this);
var $t = $ (this) [0];
if (document.selection) {
This.focus ();
var sel = Document.selection.createRange ();
Sel.text = myvalue;
This.focus ();
Sel.movestart (' character ',-l);
var wee = sel.text.length;
if (arguments.length = = 2) {
var L = $t. Value.length;
Sel.moveend ("character", wee + t);
T <= 0? Sel.movestart ("character", Wee-2 * t-myvalue.length): Sel.movestart ("character", Wee-t-myvalue.length);
Sel.select ();
}
} 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;
if (arguments.length = = 2) {
$t. Setselectionrange (Startpos-t, $t. Selectionend + t);
This.focus ();
}
} else {
This.value + = myvalue;
This.focus ();
}
}
})
How to use:
/**
* Click the emoticon button to insert the expression method
* @param {string} dom any child node
* @param {Object} Event event Object
*/
Fc.emote = Functi On (DOM, event) {
if (DOM) {
This.setparam (DOM);
} else {
return false;
}
var that = $ (DOM);
var e = window.event | | event;
if (e.stoppropagation) {
e.stoppropagation ();
} else{
E.cancelbubble = true;
}
//Show emoticon popup
$ ('. Fresh-dialog-emote '). Removeclass (' hide ');
//Current text box textarea
var _currenttextarea = This.param.form;
//Click the emoticon to insert the text box
$ ('. Fresh-dialog-emote '). Off (' click ', '. Fresh-jssmilies li '). On (' click ', '. Fresh-jssmilies li '), function () {
var _val = $ (this). Data (' action ');
Console.log (_val)
Console.log (_currenttextarea.length)
_currenttextarea.focus ();
_currenttextarea.insertcontent (_val);
$ ('. Fresh-dialog-emote '). addclass (' hide ');
})
}
Click on the Emoticons button to pop up the expression pop-up layer
$ ('. Fresh-list '). Off (' click ', '. fresh-comment-emote-btn '). On (' click ', '. Fresh-comment-emote-btn ', function (event) {
Fresh.comment.emote (this, event);
});
JS implements a plug-in that inserts picture text at the text box text field cursor (and the cursor is displayed after inserting content)