你好,这个问题没有原生的接口直接实现,但可以通过JSDOM的特性来实现,参考以下代码:
- import 'bootstrap.css';
- import '@grapecity/wijmo.styles/wijmo.css';
- import './styles.css';
- //
- import * as input from '@grapecity/wijmo.input';
- import { getData } from './data';
- //
- document.readyState === 'complete' ? init() : window.onload = init;
- //
- function init() {
- (function ($, undefined) {
- $.fn.getCursorPosition = function () {
- var el = $(this).get(0);
- var pos = 0;
- if ('selectionStart' in el) {
- pos = el.selectionStart;
- } else if ('selection' in document) {
- el.focus();
- var Sel = document.selection.createRange();
- var SelLength = document.selection.createRange().text.length;
- Sel.moveStart('character', -el.value.length);
- pos = Sel.text.length - SelLength;
- }
- return pos;
- }
- })(jQuery);
- let theCombo = new input.ComboBox('#theCombo', {
- displayMemberPath: 'country',
- itemsSource: getData()
- });
- //
- let theAutoComplete = new input.AutoComplete('#theAutoComplete', {
- displayMemberPath: 'country',
- itemsSource: getData()
- });
- $("#btn").click(function(){
- var host = theAutoComplete.hostElement;
- var input = $(host).find("input");
- console.log(input.getCursorPosition());
- });
- }
复制代码
在这里可以看到效果:
https://demo.grapecity.com.cn/wi ... ete/Overview/purejs
注意需要给html页面上加一个id是btn的按钮 |