【发布时间】:2014-01-09 07:04:06
【问题描述】:
在我的 jqGrid 中,我有一个文本框和一个按钮。单击该按钮时,我需要保存用户键入的文本框的值。我试过了,但我没有得到输出。
以下是我的colModel:
{ name: 'Price', index: 'Price', width: 120, editable: true, edittype: "text", formatter: generateTextBox },
{ name: 'Checkout', index: 'Checkout', width: 120, editable: true, formatter: generateCheckoutBtn }
我已经编写了自定义格式化程序来生成文本框和按钮,代码如下,
function generateTextBox(cellvalue, options, rowObject) {
return '<input type="text" size="10" maxlength="15" />';
}
然后我写了一个函数来检索文本框的值,并在 generateCheckoutBtn 格式化程序中的 onclick 中调用它,如下
function generateCheckoutBtn(cellvalue, options, rowObject) {
return '<button onclick="return getTextBoxValue(' + rowObject.Id + ')">Checkout</button>';
}
getTextBoxValue函数,如下
function getTextBoxValue(SelectedId) {
alert("RowId: " + SelectedId);
var txt = jQuery("#CheckList").jqGrid('getCell', SelectedId, 'Price');
alert("" + txt);
}
该函数正确返回rowId,使用警报检查,但它返回txt的警报,
<input type="text" size="10" maxlength="15" />
我不知道如何获取用户在文本框中输入的单元格内容,然后将其保存到数据库中。当用户点击 Checkout 按钮而不输入文本时,我必须发出 alert。
任何帮助将不胜感激!
【问题讨论】:
-
Fiddle 可以很好地解决这个问题。
标签: javascript jquery jqgrid