我有一段時間的屏幕鍵盤工作良好。一個編輯文本字段的按鈕。將jQuery添加到組合中
我最近不得不添加jQuery到系統,現在它不再工作。按下按鈕不會執行任何操作,因爲按下按鈕時文本輸入不再有焦點,而且我無法從jscript重新對焦。
輸入HTML(請注意使用的優秀jq_watermark - 的原因,我需要的jQuery):
<input class="search jq_watermark" id="barcode" name="barcode" type="text" title="Please enter search criteria."/>
下面是一個按鈕的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();
});
p.S.我知道周圍整齊的jQuery彈出式鍵盤,並且很樂意用他們的替換我的,但現在不是一種選擇。