项目中可能会遇到自定义格式的问题,之前没接触过这么方面,后来看官方文档,总结了一个大致的模版
主要js如下:
<script type="text/javascript">
// The javascript executed specified by JQGridColumn.EditTypeCustomCreateElement when EditType = EditType.Custom
// The two parameters are the value of the field
// and the edit options - passed from JQGridColumn.EditFieldAttributes collection
function createFreightEditElement(value, editOptions) {
var span = $("<span>");
var label = $("<span>", { html: "0" });
var radio = $("<input>", { type: "radio", val: "0", name: "freight", id: "zero", checked: (value != 25 && value != 50 && value != 100) });
var label1 = $("<span>", { html: "25" });
var radio1 = $("<input>", { type: "radio", val: "25", name: "freight", id: "fifty", checked: value == 25 });
var label2 = $("<span>", { html: "50" });
var radio2 = $("<input>", { type: "radio", val: "50", name: "freight", id: "fifty", checked: value == 50 });
var label3 = $("<span>", { html: "100" });
var radio3 = $("<input>", { type: "radio", val: "100", name: "freight", id: "hundred", checked: value == 100 });
span.append(label).append(radio).append(label1).append(radio1).append(label2).append(radio2).append(label3).append(radio3);
return span;
}
// The javascript executed specified by JQGridColumn.EditTypeCustomGetValue when EditType = EditType.Custom
// One parameter passed - the custom element created in JQGridColumn.EditTypeCustomCreateElement
function getFreightElementValue(elem) {
return $(elem).find("input:radio:checked").val();
}
</script>
大家可以参考官方文档,自己总结:http://www.trirand.net/examples/grid/editing_data/inline_edit_types/default.aspx
本文介绍了一种在项目中实现自定义格式的方法,通过JavaScript代码展示了如何创建和获取自定义编辑元素的值,适用于需要特定输入格式的场景。

被折叠的 条评论
为什么被折叠?



