BEFORE CODE
$( 'input[type=button]' ).on('click', function(){
var cursorPos = $('#spotsettings-template-code').prop('selectionStart');
var v = $('#spotsettings-template-code').val();
var textBefore = v.substring(0, cursorPos );
var textAfter = v.substring( cursorPos, v.length );
$('#spotsettings-template-code').val( textBefore+ $(this).val() +textAfter );
});
AFTER CODE : example down here
$( 'a' ).on('click', function(){
var cursorPos = $('#text').prop('selectionStart');
var v = $('#text').val();
var textBefore = v.substring(0, cursorPos );
var textAfter = v.substring( cursorPos, v.length );
$('#text').val( textBefore+ $(this).val() +textAfter );
});
But dont work ,,, its possible change input[type=button] to be or
<form>
<textarea id="text" cols="40" rows="3"> </textarea>
<a>[tag_label]</a> or <span>[tag_label]</span>
</form>
Sorry for bad english! Regards Regga
found the answer from tamplar
$('span').on('click', function(){
var cursorPos = $('#text').prop('selectionStart');
var v = $('#text').text();
var textBefore = v.substring(0, cursorPos );
var textAfter = v.substring( cursorPos, v.length );
$('#text').val( textBefore+ $(this).text() +textAfter );
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.