【发布时间】:2014-09-19 12:32:21
【问题描述】:
我有一个使用 php 的 jqgrid。在其中一列中,我想使用两个单选按钮(是/否)。我为此使用了自定义格式化程序..
$(function () {
function myelem (value, options) {
var radio1 = document.createElement('input');
radio1.id = 'radY';
radio1.type = 'radio';
radio1.name = 'appr';
radio1.value = 'Yes';
var radio2 = document.createElement('input');
radio2.id = 'radN';
radio2.type = 'radio';
radio2.name = 'appr';
radio2.value = 'No';
var label1 = document.createElement('label');
label1.setAttribute('for', radio1.id);
label1.innerHTML = 'Yes';
var label2 = document.createElement('label');
label2.setAttribute('for', radio2.id);
label2.innerHTML = 'No';
var container = document.createElement('div');
container.appendChild(radio1);
container.appendChild(label1);
container.appendChild(radio2);
container.appendChild(label2);
return container;
}
function myvalue(elem, operation, value) {
if(operation === 'get') {
return $(elem).val();
}
else if(operation === 'set') {
$('input',elem).val(value);
}
}
$("#list").jqGrid({
url: "fetch.php?sqlselect=1",
datatype: "json",
mtype: "GET",
colNames: ["Role", "Region", "Approved"],
colModel: [
{ name: "role", width: 60,editable:true},
{ name: "region", width: 60,editable:true},
{ name: "approved", width:250, editable:true, edittype:"custom", editoptions: {custom_element: myelem, custom_value:myvalue}}
],
onSelectRow: function(id){
if(id && id!==lastSel){
jQuery('#list').restoreRow(lastSel);
lastSel=id;
}
jQuery('#list').jqGrid('editRow',id,
{
keys : true,
url : "edit.php"
} );
},
.............
除单选按钮列外,编辑时一切正常。我可以看到单选按钮 onClick。但是一旦我按下回车,单选按钮的值就不会传递到我的编辑页面。这是可以理解的,因为 myval 函数正在读取 div 元素而不是 radio 元素。由于有两个单选按钮(具有相同的名称,所以此时只能检查一个是/否),并且它不是像文本框这样的单个实体,为了“返回”一个髓鞘,我必须使用一个 div .有没有办法可以获取无线电元素值?
【问题讨论】:
标签: javascript php html jqgrid