gpt4 book ai didi

javascript - jquery.mentionsInput 在移动设备上不起作用

转载 作者:行者123 更新时间:2023-11-28 05:47:06 24 4
gpt4 key购买 nike

我在我的项目中使用jquery.mentionsInput。该插件在桌面上运行良好,但在移动设备上运行不佳。这是我的代码。 Alert() 用于测试检查该功能是否正常工作。

$('textarea.mention').mentionsInput({

onDataRequest:function (mode, query, callback) {
alert("To test on mobile");
searchVal = query;

$.ajax({
type: "GET",
dataType: "json",
url: rootPath()+"user/tagFriends/"+searchVal,

success: function(data){
data = _.filter(data, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > - 1 });
callback.call(this, data);
}

});


}
});

这是插件link 。该插件也无法在移动设备上运行。提前致谢。抱歉我的英语不好。

最佳答案

在文件 jquery.mentionsInput.js 中,您可以像这样修改 2 个函数 onInputBoxInput() 和 onInputBoxKeyPress()

function onInputBoxInput(e) {
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {//certain versions of android mobile browser don't trigger the keypress event.
if(e.keyCode !== KEY.BACKSPACE) {
var typedValue = String.fromCharCode(e.which || e.keyCode); //Takes the string that represent this CharCode
inputBuffer.push(typedValue); //Push the value pressed into inputBuffer
}
}
updateValues();
updateMentionsCollection();

var triggerCharIndex = _.lastIndexOf(inputBuffer, settings.triggerChar); //Returns the last match of the triggerChar in the inputBuffer
if (triggerCharIndex > -1) { //If the triggerChar is present in the inputBuffer array
currentDataQuery = inputBuffer.slice(triggerCharIndex + 1).join(''); //Gets the currentDataQuery
currentDataQuery = utils.rtrim(currentDataQuery); //Deletes the whitespaces
_.defer(_.bind(doSearch, this, currentDataQuery)); //Invoking the function doSearch ( Bind the function to this)
}
}

//Takes the keypress event
function onInputBoxKeyPress(e) {
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(!isAndroid) {
if(e.keyCode !== KEY.BACKSPACE) { //If the key pressed is not the backspace
var typedValue = String.fromCharCode(e.which || e.keyCode); //Takes the string that represent this CharCode
inputBuffer.push(typedValue); //Push the value pressed into inputBuffer
}
}
}

在你的index.html中

将此代码添加到页面底部

<script>


var sendBoxElem = $('textarea.mention');
sendBoxElem.bind("input", function(e) {
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
var char = this.value.charCodeAt(this.value.length - 1);
//$scope.data = char;
if(e.keyCode === undefined){
e.keyCode = char;
}
return true;
}
});

</script>

请告诉我这是否有效

关于javascript - jquery.mentionsInput 在移动设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38419591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com