我有一段时间的屏幕键盘工作良好。一个编辑文本字段的按钮。将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弹出式键盘,并且很乐意用他们的替换我的,但现在不是一种选择。