首先,我将提交与这里发布的代码片段相关的几个不同的问题。因此,如果你看到其他问题并认为"嘿,这是重复的,我看过那个代码",它实际上不是。我想确保每个答案都能回答不同的问题。这里有一个例子:我有下面的jqgrid,当用户只输入字段的前半部分时,我试图将屏蔽从"__"更改为"00"。方法被调用,值改变了,但它仍然显示旧的值。我使用的是jqgrid 4.2版本。网格:
WorkSchedule.prototype.init = function() {
var self = this;
self.jqgridParms = {
datatype: "local",
height: 'auto',
width: 700,
colNames: ["Week", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Total"],
colModel: [// very much dummy stuff here.
{name: "Week", index: "Week", width: 50, editable: false },
{ name: "Sun", index: "Sun", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
}, align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "Mon", index: "Mon", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
}, align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "Tues", index: "Tues", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
},
align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "Wed", index: "Wed", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
},
align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "Thurs", index: "Thurs", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
},
align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "Fri", index: "Fri", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
},
align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "Sat", index: "Sat", width: 85, editable: true, edittype: "text", editoptions: { size: 20, maxlength: 30,
dataInit: function(elem) {
$(elem).mask("99:99");
}
},
align: "center", formatter: timeEntryFormat, editrules: { custom: true, custom_func: validHourEntry }
},
{ name: "WeekTotal", index: "WeekTotal", width: 55, editable: true, align: "center" }
],
multiselect: false,
caption: "Manage Work Schedule",
rowNum: 10,
cellEdit: true,
gridComplete: function() {
calculateTotal();
},
beforeSaveCell: function(rowid,cellname,value,iRow,iCol) {
formatFromMask(rowid, cellname, value, iRow, iCol);
},
afterSaveCell: function() {
calculateTotal();
},
cellsubmit: "clientArray"
}
}
function formatFromMask(rowid, cellname, value, iRow, iCol) {
if (typeof value !== "undefined") {
value = value.replace(/_/g, "0");
return value;
}
}
好的,我找到了一个简单的答案,那就是将掩码设置为"00:00"。它提出了一个单独的问题,但解决了这里的问题。