jquery在asp.net的应用
没事的时候写的
1 <script type="text/javascript">
2 var answerId;
3 $(document).ready(function(){
4 findQuestion();
5 findAnswer();
6 var opt='<%=Request["opt"] %>';
7 if(opt==null || opt==''){
8 opt='noTeacher';
9 }
10 $('#btnBack').click(function(){goBack(opt)});
11 $('#btnBack1').click(function(){goBack(opt);});
12 $('#btnTeacherAnswer').click(textDisplay);//显示 隐藏
13 $('#btnOK').click(TeacherAnswers);//导师的回答
14 $('#btnMoreDelete').click(doDeleteMore);//批量删除
15 $('#chkAll').click(chkAll);//全选
16
17
18 });
19
20 //全选
21 function chkAll()
22 {
23 var chk=document.getElementsByName("chk");
24 var chkAll=document.getElementById("chkAll");
25 for(i=0;i<chk.length;i++){
26 chk[i].checked =chkAll.checked;
27 }
28 }
29
30 //批量删除
31 function doDeleteMore(){
32 if(!confirm("确定批量删除?"))
33 return false;
34 var chk=document.getElementsByName("chk");
35 var ids='';
36 for(i=0;i<chk.length;i++){
37 if(chk[i].checked==true){
38 ids+=chk[i].value+",";
39 }
40 }
41 ids=ids.substring(0,ids.length-1);
42 if(ids==null || ids==''){
43 alert('请选择你要删除的数据!!');
44 return false;
45 }
46 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=doDeleteMore&id="+ids;
47 $.ajax({
48 url:url,
49 dataType:'json',
50 type:'post',
51 success:function(response){
52 alert(response);
53 $('#dateGridAnswer').empty();//将大层dateGridAnswer清空
54 findAnswer();
55 }
56 });
57 }
58
59 //提交导师回答的问题
60 function TeacherAnswers(){
61 var id='<%=Request["id"] %>';//问题的id
62 var context=$('#txtTeacherAnswerContext').val(); //回答的内容
63 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=TeacherAnswers&studyQuestionId="+id+"&answer="+encodeURI(context);
64 $.ajax({
65 url:url,
66 dataType:'json',
67 type:'post',
68 success:function(response){
69 $('#fsContext').hide();
70 $('#dateGridAnswer').empty();//将大层dateGridAnswer清空
71 findAnswer();
72 }
73 });
74 }
75 var flag=true;//用做标示
76 //显示隐藏
77 function textDisplay(){
78 if(flag==true){
79 $('#fsContext').show();
80 $('#txtTeacherAnswerContext').focus();
81 $('#btnTeacherAnswer').attr("value","隐藏回答");
82 flag=false;
83 }
84 else if(flag==false){
85 $('#fsContext').hide();
86 $('#btnTeacherAnswer').attr("value","我来回答");
87 flag=true
88 }
89
90 }
91
92 //审核
93 function ApprovedClick(obj){
94 var id=obj.id;
95 if(!confirm("确定审核此记录?"))
96 return false;
97 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=AnswerApproved&id="+id;
98 $.ajax({
99 url:url,
100 dataType:'text',
101 type:'post',
102 success:function(response){
103 alert(response);
104 $('#dateGridAnswer').empty();//将大层dateGridAnswer清空
105 findAnswer();
106 }
107 });
108 }
109 //反审核
110 function RevertApprovedClick(obj){
111 var id=obj.id;
112 if(!confirm("确定要反审核?"))
113 return false;
114 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=AnswerRevertApproved&id="+id;
115 $.ajax({
116 url:url,
117 dataType:'text',
118 type:'post',
119 success:function(response){
120 alert(response);
121 $('#dateGridAnswer').empty();//将大层dateGridAnswer清空
122 findAnswer();
123 }
124 });
125 }
126
127 //获取问题
128 function findQuestion(){
129 var id='<%=Request["id"] %>';
130 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=findQuestion&id="+id;
131 var html='';
132 $.ajax({
133 url:url,
134 dataType:'json',
135 type:'post',
136 success:function(response){
137 $.each(response,function(i){
138 html+="<div style='font-size:12px'>";
139 html+="<b>标题:</b>"+response[i].QuestionTitle+"<p>";
140 html+="<b>问题:</b>"+response[i].QuestionContent+"<p>";
141 if(response[i].UserName==''||response[i].UserName==null){
142 response[i].UserName="匿名";
143 }
144 html+="<b>提问人:</b>"+response[i].UserName+" ";
145 html+="<b>提问时间:</b>"+response[i].CreatTimeShort;
146 html+="</div>";
147 answerId=response[i].Id;
148 $('#dataGrid').append(html);
149 });
150 }
151 });
152 }
153
154 //获取问题的答案
155 function findAnswer(){
156 var id='<%=Request["id"] %>';
157 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=findAnwser&id="+id;
158
159 $.ajax({
160 url:url,
161 dataType:'json',
162 type:'post',
163 success:function(response){
164 if(response==null ||response==''){
165 $('#dateGridAnswer').append("<div style='color:red;padding-left:10px;padding-top:10px'>暂时没有人回答</div>");
166 }
167 $.each(response,function(i){
168 var html='';//在这里声明变量可以去除出现重复的数据,而且这里的i都是可以取得到的,empty()只是把前面的清空但有的得不到i
169 html+="<div style='margin-top:10px;border:1px #cccccc dashed;padding-top:10px;padding-left:10px;width:100%;float:left'>";
170 html+="<div style='width:80%;float:left'><b>回答的内容:</b>"+response[i].Answer+"<p>";
171 if(response[i].UserName==null || response[i].UserName==''){
172 response[i].UserName="匿名";
173 }
174 html+="<b>回答人:</b>"+response[i].UserName+" ";
175 html+="<b>回答时间:</b>"+response[i].CreatTimeShort+" ";
176 html+="<input type='button' id='"+response[i].Id+"' value='审核' onclick='ApprovedClick(this)'/> <input type='button' id='"+response[i].Id+"' onclick='RevertApprovedClick(this)' value='反审核'/>";
177 html+=" 是否审核:<span style='color:green'>"+response[i].FlagApprovedSign+"</span>";
178 html+=" <input type='button' value='删除' onclick='doDeleteOne(this)' id='"+response[i].Id+"'/></div><div style='width:5%;float:left'><input type='checkbox' id='chk' value='"+response[i].Id+"' /></div>";
179 html+="</div>";
180 $('#dateGridAnswer').append(html);
181 });
182 }
183 });
184
185 }
186
187 //单条删除
188 function doDeleteOne(obj){
189 if(!confirm("确定要删除?"))
190 return false;
191 var id=obj.id;
192 var url=getAppPath()+"/Admin/Handler/StudyQuestionHandler.ashx?cmd=doDeleteOne&id="+id;
193 $.ajax({
194 url:url,
195 dataType:'json',
196 type:'post',
197 success:function(response){
198 alert(response);
199 $('#dateGridAnswer').empty();//将大层dateGridAnswer清空
200 findAnswer();
201 }
202 });
203 }
204
205 function getAppPath(){
206 var path = '<% =HttpContext.Current.Request.ApplicationPath%>';
207 path = path.length == 1 ? "": path;
208 return path;
209 }
210
211 function setDate(s)
212 {
213
214 if(!s) return '';
215 var d = new Date(parseInt(s.match(/\d+/)));
216 return [d.getFullYear(),d.getMonth() + 1,d.getDate()].join('-');
217 }
218 //返回
219 function goBack(opt){
220 var url;
221 if(opt=='oneTeacher'){
222 url=getAppPath()+"/Admin/TeacherManager/TeacherPersonal.aspx";
223 }
224 else if(opt=='noTeacher'){
225 url=getAppPath()+"/Admin/TeacherManager/Index.aspx";
226 }
227 document.location.href=url;
228 }
229
230 </script>