小小宇

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

前台代码:

 

代码
1 <div id="actionwindow" style="width: 500px" runat="server" class="window">
2 <div class="title">
3 数据查询
4 </div>
5 <div id="queryAll" class="content05">
6 <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="left:18px; position:relative" >
7 <tr>
8 <td style="width:158px;border:1px solid #FFFFFF;" align="center">
9 字段
10 </td>
11 <td style="width:52px;border:1px solid #FFFFFF;" align="center">
12 操作符
13 </td>
14 <td style="width:154px;border:1px solid #FFFFFF;" align="center">
15 字段值
16 </td>
17 <td style="width:78px;border:1px solid #FFFFFF;" align="center">
18 关系
19 </td>
20 <td ></td>
21 </tr>
22 </table>
23 <input type="hidden" id="hidValidateField" runat="server" />
24 <input type="hidden" id="hidValidateOpration" runat="server" />
25 <input type="hidden" id="hidValidateContent" runat="server" />
26 <input type="hidden" id="hidValidateRelation" runat="server" />
27 <div id="search0" style="position:relative;left:18px" >
28 <asp:DropDownList ID="ddlQuery" name="ddlQuery" runat="server"></asp:DropDownList></div>
29 </div>
30 <div style="padding-left: 20px" id="div_Error">
31 <label id="labError" runat="server">
32 </label>
33 </div>
34 <br />
35 <table width="100%" height="36" border="0" align="center" cellpadding="0" cellspacing="0" >
36 <tr>
37 <td align="center">
38 <input id="queryFields" type="hidden" runat="server" />
39 <asp:Button runat="server" class="btn04" ID="lbtnQuery" Text="查询" OnClick="lbtnQuery_Click" />
40 &nbsp;
41 <asp:Button ID="lbtnClose" runat="server" OnClientClick="jWindow.close($('#actionwindow')); return false;"
42 class="btn04" Text="关闭" />
43 </td>
44 </tr>
45 </table>
46 </div>

 

JS文件代码:

 

代码
1 $(function () {
2
3 //下拉列表选择事件
4   $("#ddlQuery").live("change", function () {
5 if ($(this).val() != 0) {
6 var str = "";
7 str = '<select id="' + $(this).val() + '" name="ddlQuery">'
8 str += '<option value="1">等于</option>';
9 str += '<option value="2">大于</option>';
10 str += '<option value="3">小于</option>';
11 str += '<option value="4">包含</option></select>';
12 // if ($(this).find("option:selected").text().indexOf("时间") > 0) {
13 // str += '<input id=\"' + $(this).val() + '\" type=\"text\"' + " click='javascript:alert('dd')' />";
14 // }
15 // else {
16   str += '<input name="txtContent" id="' + $(this).val() + '" type="text" />';
17 // str += '<input name="txtContent" id="' + 'txtContent' + '" type="text" />';
18 // }
19  
20 str += '<select name="ddlSelect" id="' + $(this).val() + '">';
21 str += '<option value="0">--请选择--</option>';
22 str += '<option value="1">并且</option>';
23 str += '<option value="2">或者</option>';
24 $(this).nextAll().remove().end().parent().append(str);
25 }
26 else {
27 $(this).nextAll().remove();
28 }
29 $(this).next().next().click(function () {
30 if ($(this).prev().prev().find("option:selected").text().indexOf("时间") > 0) {
31 $(this).attr("readonly", true);
32 WdatePicker({ readonly: true, highLineWeekDay: true });
33 }
34 });
35 });
36
37 ///添加事件
38   $("select[name='ddlSelect']").live("change", function () {
39 if ($(this).val() != 0) {
40 if ($(this).parent().next().find("select").get(0) == undefined) {
41 var Did = "search" + i;
42 var str = '<div id="' + Did + '"><img alt="删除" src="http://images.cnblogs.com/delete.png" id="img_delete" /></div>';
43 $("#queryAll").append(str);
44 $("#ddlQuery:first").clone().appendTo("#" + Did);
45 $("#" + Did + " > select").val("0");
46 i++;
47 }
48 }
49 else {
50 $(this).parent().nextAll().remove();
51 }
52 });
53
54 ///删除查询条件事件
55 $("#img_delete").live("click", function () {
56 $(this).parent().remove();
57 });
58
59 ///确认按钮
60 $("#lbtnQuery").click(function () {
61 var intFalg = 0;
62 var floatFalg = 0;
63 if (CheckInput()) {
64 $("div[id*=search]").each(function () {
65 if ($(this).find("input[type='text']").get(0) != undefined) {
66 if ($(this).find("input[type='text']").attr("id").indexOf("i") == 0) {
67 if (!IsInt($(this).find("input[type='text']").val()) || $.trim($(this).find("input[type='text']").val()).length > 10) {
68 intFalg = 1;
69 }
70 }
71 else if ($(this).find("input[type='text']").attr("id").indexOf("f") == 0) {
72 if (isNaN($(this).find("input[type='text']").val()) || $.trim($(this).find("input[type='text']").val()).length > 10) {
73 floatFalg = 1;
74 }
75 }
76 }
77 });
78 if (intFalg == 1) {
79 alert("人员数请输入小于10位的整数");
80 return false;
81 }
82 else if (floatFalg == 1) {
83 alert("资产数请输入小于10位的数字");
84 return false;
85 }
86 else {
87 var strQuery = "[";
88 // alert($("#search0").children().eq(0).val());
89 $("div[id*=search]").each(function () {
90 if ($(this).attr("id") == "search0") {
91 strQuery += '{"field":"' + $(this).children().eq(0).val() + '","opration":"' + $(this).children().eq(1).val() + '","content":"' + $(this).children().eq(2).val() + '","relation":"' + $(this).children().eq(3).val() + '"},'
92 }
93 else {
94 strQuery += '{"field":"' + $(this).children().eq(1).val() + '","opration":"' + $(this).children().eq(2).val() + '","content":"' + $(this).children().eq(3).val() + '","relation":"' + $(this).children().eq(4).val() + '"},'
95 }
96 });
97 strQuery = strQuery.substring(0, strQuery.length - 1) + "]";
98 $("#queryFields").val(strQuery);
99 jWindow.close($('#actionwindow'));
100 }
101
102 }
103 else {
104 return false;
105 }
106 });
107 });
108

 

查询条件输入验证:

 

代码
1 function CheckInput() {
2 var result = $("#form1").validate({
3 rules: {
4 hidValidateField: {//字段
5   FieldRequired: true
6 },
7 hidValidateContent: {//字段值
8   ContentRequired: true
9 },
10 hidValidateRelation: {//关系
11 RelationRequired: true
12 }
13 },
14 errorClass: "errorClass",
15 //方式一
16 errorLabelContainer: $("#div_Error"),
17 wrapper: 'li'
18
19 });
20 return result.form();
21 }
22
23 ///字段必选
24 jQuery.validator.addMethod("FieldRequired", function (value, element) {
25 var falg = 0;
26 $("select[name='ddlQuery']").not(":first").each(function () {
27 if ($(this).val() == "0") {
28 falg = 1;
29 }
30 });
31 return falg == 0;
32
33 }, "*字段必选");
34
35 ///字段值必填
36 jQuery.validator.addMethod("ContentRequired", function (value, element) {
37 var falg = 0; //txtContent
38 $("input[name='txtContent']").each(function () {
39 if ($.trim($(this).val()) == "") {
40 falg = 1;
41 }
42 });
43 return falg == 0;
44
45 }, "*字段值必填");
46
47 ///关系必选
48 jQuery.validator.addMethod("RelationRequired", function (value, element) {
49 var falg = 0; //ddlSelect
50 $("select[name='ddlSelect']").not(":last").each(function () {
51 if ($(this).val() == "0") {
52 falg = 1;
53 }
54 });
55 return falg == 0;
56
57 }, "*关系必选");
58
59 //判断是否为整数
60 function IsInt(v) {
61 var vArr = v.match(/^[0-9]+$/);
62 if (vArr == null) {
63 return false;
64 }
65 else {
66 return true;
67 }
68 }

 

posted on 2010-12-22 14:27  小小宇  阅读(960)  评论(1)    收藏  举报