htmlBuilder.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var __html_builder = {
builderListPageBtns : function(btns){
var text = "";
var _btn_datas = [];
if(btns){
_btn_datas = btns;
} else{//default
_btn_datas = [
{role : "edit", text : "编辑"},
{role : "delete", text : "删除"}
];
}
_btn_datas.forEach(function(obj,index){
var _edit = $("<a style='margin-left:10px'></a>");
_edit.attr("role", obj.role);
if(obj.data){
_edit.attr("data", obj.data);
}
_edit.text(obj.text);
text += _edit.get(0).outerHTML;
});
return text;
},
buildSelect : function(param){
var _select = $("<select></select>");
_select.attr(param.attr);
_select.css(param.css);
var _option_datas = param.option_datas || [] ;
var _options_html = "<option value=\"\">请选择</option>";
_option_datas.forEach(function(_optioin_val,_index){
_options_html += "<option value=\""+ _optioin_val.en_name +"\">"+ _optioin_val.cn_name +"</option>";
});
_select.append(_options_html);
return _select;
},
buildInput : function(_props){
var text = "";
var default_props = { type : "text"};
if(_props){
$.extend(default_props, _props);
}
var _input = $("<input />");
$.each(default_props,function(key,val){
_input.attr(key,val);
})
return _input.get(0).outerHTML;
}
}