私はしばらくの間、オンスクリーンキーボードが正常に機能していました。
最近、システムにjQueryを追加する必要がありましたが、現在は機能していません。ボタンを押してもテキスト入力にフォーカスがなくなり、jscriptから再度フォーカスできなくなるため、ボタンを押しても何も起こりません。
入力html(優れたjq_watermarkの使用に注意してください-jQueryが必要な理由):
<input class="search jq_watermark" id="barcode" name="barcode" type="text" title="Please enter search criteria."/>
ボタンの1つのhtmlは次のとおりです。
<td onclick="addChar('Q')"><button class="osk" id="Key_Q" value="Q">Q</button></td>
これがaddCharスクリプトです。フィールドに焦点を合わせるための多くの試みに注意してください。jQueryが存在するようになったため、すべて失敗します。
// The field the keyboard should edit.
field = document.forms['main'].elements.item('barcode');
function addChar(c) {
console.log("Char("+c+")");
field.focus();
if(field.maxLength == -1 || field.value.length < field.maxLength) {
// Handle different browsers.
if (field.selectionStart || field.selectionStart == '0') {
var start = field.value.substr(0,field.selectionStart);
var end = field.value.substr(field.selectionEnd,field.length);
field.value = start + c + end;
} else if (document.selection) {
field.focus();
var range = document.selection.createRange();
range.text = c;
range.moveStart('textedit',1);
range.select();
} else {
field.value = field.value + c;
}
field.focus();
}
return false;
}
ボタンがフォームを送信するのを止めるためにこれを追加する必要がありました。これは私が新しいものを置く必要がある場所だと思いますが、jQueryに慣れていないので、私には何がわかりません:
$("button.osk").click(function(event){
// Stop it submitting in case the keyboard is inside a form.
event.preventDefault();
});
PS私は周りのきちんとしたjQueryポップアップキーボードを知っていて、私のものをそれらのものに置き換えたいと思っていますが、それは今のところオプションではありません。