Html 三星Tizen智能电视网络应用程序键盘UI上的左箭头键或右箭头键无法处理输入文本

Html 三星Tizen智能电视网络应用程序键盘UI上的左箭头键或右箭头键无法处理输入文本,html,input,samsung-smart-tv,tizen-web-app,Html,Input,Samsung Smart Tv,Tizen Web App,我正在开发一个三星Tizen智能电视应用程序,其中我使用了一个HTML格式的输入标记。我在文本框中输入了一些内容,并尝试使用三星电视键盘上的左箭头和右箭头按钮左右移动光标,但它不起作用 config.xml <?xml version="1.0" encoding="UTF-8"?> <widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" version="1

我正在开发一个三星Tizen智能电视应用程序,其中我使用了一个HTML格式的输入标记。我在文本框中输入了一些内容,并尝试使用三星电视键盘上的左箭头和右箭头按钮左右移动光标,但它不起作用

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" version="1.0.2" viewmodes="maximized">
    <tizen:application id="wJfsfi5g6A4.MYAPP" package="wJfsfi5g6A4" required_version="2.3"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.normal.1080.1920"/>
    <icon src="icon.png"/>
    <name>MYAPP</name>
    <tizen:privilege name="http://developer.samsung.com/privilege/productinfo"/>
    <tizen:privilege name="http://developer.samsung.com/privilege/network.public"/>
    <tizen:privilege name="http://tizen.org/privilege/tv.inputdevice"/>
    <tizen:profile name="tv-samsung"/>
    <tizen:setting screen-orientation="landscape" context-menu="enable" background-support="enable" encryption="enable" install-location="auto" hwkey-event="enable"/>
</widget>

MYAPP

要解决此问题,您必须获取当前位置并移动到当前位置-1(如果按下左箭头键),或当前位置+1(如果按下右箭头键)

var leftmove,rightmove;
function controlLeftArrowKeys(){
    var input = document.getElementById('name');
    if(input.value.length == 0){
        return;
    }
    var currentpos =input.selectionStart; //getting current postion of cursor 
    leftmove=currentpos-1;
    setCaretPosition(input, leftmove);
}
function controlrightArrowKeys(){
    var input = document.getElementById('name');
    if(input.value.length == 0){
        return;
    }
    var currentpos =input.selectionStart;  //getting current postion of cursor
    rightmove= currentpos+1;
    setCaretPosition(input, rightmove);
}
function setCaretPosition(ctrl, pos) {
      // Modern browsers
      if (ctrl.setSelectionRange) {
        ctrl.focus();
        ctrl.setSelectionRange(pos, pos);

      // IE8 and below
      } else if (ctrl.createTextRange) {
        var range = ctrl.createTextRange();
        range.collapse(true);
        range.moveEnd('character', pos);
        range.moveStart('character', pos);
        range.select();
      }
    }
因此,您只需在按键盘左右键时调用
controlLeftArrowKeys
controlrightArrowKeys
函数即可