[英]ASP.NET postBack post Enter Textbox on javascript
我在js中有一个脚本,它在gridview
的textBox
中搜索工作得非常好,但我每次运行这个函数时都按Enter键,因为它总是通过执行你不执行的代码来触发回发总是需要跑。 这是gridView字段 - > onfocus =“run_routine(this)”:
<input style="font-weight: bold; font-size:14px; text-align: center" id="arrivo" class='nome_<%# Eval("BOD_ABARCODE")%> colored form-control' data-barcode='<%# Eval("BOD_ABARCODE")%>' maxlength="18" name='<%# Eval("BOD_KCODPRU").ToString +"-" + Eval("BOD_KCODCAB").ToString %>' onkeyup="enter(this)" oncopy="return false" oncut="return false" onfocus="esegui_routine(this)" onkeypress="return CheckNumericValue(event)" size="5" type="text" value='<%# Eval("BOD_SQUANTIT")%>' />
在js中的函数的提取下面我应该插入preventDefault但是我到处尝试过,它对我不起作用:
function esegui_routine(oggetto)
{
var barcode = $(oggetto).attr('data-barcode');
var valoreIniziale = $(oggetto).val();
$(document).removeData();
$(document).data('valoreIniziale', valoreIniziale);
$(oggetto).select();
$(oggetto).off('keypress').on('keypress', function (event) {
if (event.which == '13') {
var inserito = $(this).val();
if (inserito.length != 0) {
if (inserito.length <= 4) {
var elementi = $.fn.doppio(barcode);
if (elementi == 0) {
//BARCODE NON TROVATO : play sound e rimetto il valore precedente cancellando il barcode inserito
$.fn.playSound();
//devo rimettere il valore precedente
$(oggetto).val($(document).data('valoreIniziale')).select();
}
else if (elementi == 1) {
console.log('barcode: ' + barcode);
$.fn.settaValore(barcode, inserito);
}
else if (elementi > 1) {
var kcodpru = oggetto.name;
console.log('kcodpru: ' + kcodpru);
$.fn.settaValoreDaKcodpru(kcodpru, inserito);
}
//console.log('eccomi minore di 4')
}
}
}
});
谢谢大家的好工作
我猜你正在按一个提交按钮,这会导致表单回发。 用a代替
<button id = "btnSubmit">Submit</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.