zj.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. //首页
  2. $(function(){
  3. $(".lblRect").click(function(){
  4. $(this).addClass("active").siblings('.active').removeClass('active');
  5. });
  6. //最新动态删除
  7. $('.fcha').click(function(){
  8. $(this).parents('li').remove();
  9. });
  10. });
  11. $(function(){
  12. $('.jam').click(function(){
  13. $(this).parents('.tix').remove();
  14. });
  15. });
  16. $(function(){
  17. $(".vanish").click(function(){
  18. $(this).parents(".popup").fadeOut();
  19. });
  20. });
  21. $(function(){
  22. $change_li = $(".jlist li");
  23. $change_li.each(function(i){
  24. $(this).click(function(){
  25. $(this).addClass("active").siblings('.active').removeClass("active");
  26. $(".choice .volume").eq(i).show().siblings(".volume").hide();
  27. });
  28. });
  29. });
  30. /* 输入框输入文字限制 */
  31. $(function () {
  32. //匹配包含给定属性的元素,keyup在按键释放时发生
  33. $("#caseContent").keyup(function () {
  34. var area = $(this);
  35. //parseInt 方法返回与保存在 numString 中的数字值相等的整数。如果 numString 的前缀不能解释为整数,则返回 NaN(而不是数字)。
  36. var max = parseInt(area.attr("maxlength"), 10); //获取maxlength的值 转化为10进制,将输入到textarea的文本长度
  37. //这个判断可知max得到的是不是数字,设定的大小是多少
  38. if (max > 0) {
  39. if (area.val().length > max) { //textarea的文本长度大于maxlength
  40. area.val(area.val().substr(0, max)); //截断textarea的文本重新赋值
  41. }
  42. var yishu = area.val().length;
  43. var sheng = max - area.val().length;
  44. $("#lyishu").html(yishu);
  45. $("#lsheng").html(sheng);
  46. }
  47. });
  48. $("#caseContent").blur(function () {
  49. var area = $(this);
  50. var max = parseInt(area.attr("maxlength"), 10); //获取maxlength的值
  51. if (max > 0) {
  52. if (area.val().length > max) { //textarea的文本长度大于maxlength
  53. area.val(area.val().substr(0, max)); //截断textarea的文本重新赋值
  54. }
  55. var yishu = area.val().length;
  56. var sheng = max - area.val().length;
  57. $("#lyishu").html(yishu);
  58. $("#lsheng").html(sheng);
  59. }
  60. });
  61. });
  62. function changeCreateType(type) {
  63. var grade = parseInt($("input[name='grade']").val());
  64. if ( ! isNaN(grade) && grade >= 1 && grade <= 3) {
  65. $.get('/exams/ajaxChangeCreateType', {
  66. type: type,
  67. grade: grade
  68. }, function(result){
  69. if (result.status == 0) {
  70. $.alert(result.error);
  71. $("#classes").html("");
  72. return;
  73. }
  74. var html = '';
  75. for (var i in result) {
  76. html += '<label class="cur ml10"><input type="checkbox" name="classId[]" value="'+ result[i].class_id +'" style="vertical-align:calc();" /> '+ result[i].class_name +'</label>';
  77. }
  78. $("input[name='classIds']").val("");
  79. $("#classes").html(html);
  80. if (result.length > 0) {
  81. $("#checkClasses").show();
  82. // $("input#checkAll").click();
  83. $("input#checkAll").prop("checked", true);
  84. $("input[name='classId[]']").prop("checked", true);
  85. } else {
  86. $("#checkClasses").hide();
  87. }
  88. });
  89. } else {
  90. $.alert('请选择年级!');
  91. }
  92. }
  93. function changeGrade(grade) {
  94. var type = parseInt($("input[name='createType']").val());
  95. if ( ! isNaN(grade) && grade >= 0 && grade <= 3) {
  96. $.get('/exams/ajaxChangeCreateType', {
  97. type: type,
  98. grade: grade
  99. }, function(result){
  100. if (result.status == 0) {
  101. $.alert(result.error);
  102. $("#classes").html("");
  103. return;
  104. }
  105. var html = '';
  106. for (var i in result) {
  107. html += '<label class="cur ml10"><input type="checkbox" name="classId[]" value="'+ result[i].class_id +'" style="vertical-align:calc();" /> '+ result[i].class_name +'</label>';
  108. }
  109. $("input[name='classIds']").val("");
  110. $("#classes").html(html);
  111. if (result.length > 0) {
  112. $("#checkClasses").show();
  113. // $("input#checkAll").click();
  114. $("input#checkAll").prop("checked", true);
  115. $("input[name='classId[]']").prop("checked", true);
  116. } else {
  117. $("#checkClasses").hide();
  118. }
  119. });
  120. } else {
  121. $.alert('请选择生成方式!');
  122. }
  123. }
  124. //下拉框
  125. $(function () {
  126. function diy_select(){this.init.apply(this,arguments)};
  127. diy_select.prototype={
  128. init:function(opt)
  129. {
  130. this.setOpts(opt);
  131. this.o=this.getByClass(this.opt.TTContainer,document,'div');//容器
  132. this.b=this.getByClass(this.opt.TTDiy_select_btn);//按钮
  133. this.t=this.getByClass(this.opt.TTDiy_select_txt);//显示
  134. this.l=this.getByClass(this.opt.TTDiv_select_list);//列表容器
  135. this.ipt=this.getByClass(this.opt.TTDiy_select_input);//列表容器
  136. this.lengths=this.o.length;
  137. this.showSelect();
  138. },
  139. addClass:function(o,s)//添加class
  140. {
  141. o.className = o.className ? o.className+' '+s:s;
  142. },
  143. removeClass:function(o,st)//删除class
  144. {
  145. var reg=new RegExp('\\b'+st+'\\b');
  146. o.className=o.className ? o.className.replace(reg,''):'';
  147. },
  148. addEvent:function(o,t,fn)//注册事件
  149. {
  150. return o.addEventListener ? o.addEventListener(t,fn,false):o.attachEvent('on'+t,fn);
  151. },
  152. showSelect:function()//显示下拉框列表
  153. {
  154. var This=this;
  155. var iNow=0;
  156. this.addEvent(document,'click',function(){
  157. for(var i=0;i<This.lengths;i++)
  158. {
  159. This.l[i].style.display='none';
  160. }
  161. })
  162. for(var i=0;i<this.lengths;i++)
  163. {
  164. this.l[i].index=this.b[i].index=this.t[i].index=i;
  165. this.t[i].onclick=this.b[i].onclick=function(ev)
  166. {
  167. var e=window.event || ev;
  168. var index=this.index;
  169. This.item=This.l[index].getElementsByTagName('li');
  170. This.l[index].style.display= This.l[index].style.display=='block' ? 'none' :'block';
  171. for(var j=0;j<This.lengths;j++)
  172. {
  173. if(j!=index)
  174. {
  175. This.l[j].style.display='none';
  176. }
  177. }
  178. This.addClick(This.item);
  179. e.stopPropagation ? e.stopPropagation() : (e.cancelBubble=true); //阻止冒泡
  180. }
  181. }
  182. },
  183. addClick:function(o)//点击回调函数
  184. {
  185. if(o.length>0)
  186. {
  187. var This=this;
  188. for(var i=0;i<o.length;i++)
  189. {
  190. o[i].onmouseover=function()
  191. {
  192. This.addClass(this,This.opt.TTFcous);
  193. }
  194. o[i].onmouseout=function()
  195. {
  196. This.removeClass(this,This.opt.TTFcous);
  197. }
  198. o[i].onclick=function()
  199. {
  200. var index = this.parentNode.index;//获得列表
  201. var type = $(this).attr("type");
  202. var name = $(this).attr("name");
  203. var examName = this.innerHTML.replace(/^\s+/,'').replace(/\s+&/,'');
  204. // This.t[index].innerHTML=This.ipt[index].value=this.innerHTML.replace(/^\s+/,'').replace(/\s+&/,'');
  205. This.t[index].innerHTML = examName;
  206. $("input[name='examName']").val(examName);
  207. // $("#checkClasses").show();
  208. $("#createTypeName").html(name);
  209. This.ipt[index].value = type;
  210. This.l[index].style.display='none';
  211. changeCreateType(type);
  212. }
  213. }
  214. }
  215. },
  216. getByClass:function(s,p,t)//使用class获取元素
  217. {
  218. var reg=new RegExp('\\b'+s+'\\b');
  219. var aResult=[];
  220. var aElement=(p||document).getElementsByTagName(t || '*');
  221. for(var i=0;i<aElement.length;i++)
  222. {
  223. if(reg.test(aElement[i].className))
  224. {
  225. aResult.push(aElement[i])
  226. }
  227. }
  228. return aResult;
  229. },
  230. setOpts:function(opt) //以下参数可以不设置 //设置参数
  231. {
  232. this.opt={
  233. TTContainer:'diy_select',//控件的class
  234. TTDiy_select_input:'diy_select_input',//用于提交表单的class
  235. TTDiy_select_txt:'diy_select_txt',//diy_select用于显示当前选中内容的容器class
  236. TTDiy_select_btn:'diy_select_btn',//diy_select的打开按钮
  237. TTDiv_select_list:'diy_select_list',//要显示的下拉框内容列表class
  238. TTFcous:'focus'//得到焦点时的class
  239. }
  240. for(var a in opt) //赋值 ,请保持正确,没有准确判断的
  241. {
  242. this.opt[a]=opt[a] ? opt[a]:this.opt[a];
  243. }
  244. }
  245. }
  246. var TTDiy_select=new diy_select({ //参数可选
  247. TTContainer:'diy_select',//控件的class
  248. TTDiy_select_input:'diy_select_input',//用于提交表单的class
  249. TTDiy_select_txt:'diy_select_txt',//diy_select用于显示当前选中内容的容器class
  250. TTDiy_select_btn:'diy_select_btn',//diy_select的打开按钮
  251. TTDiv_select_list:'diy_select_list',//要显示的下拉框内容列表class
  252. TTFcous:'focus'//得到焦点时的class
  253. });//如同时使用多个时请保持各class一致.
  254. });
  255. //下拉框
  256. $(function () {
  257. function diy_select2(){this.init.apply(this,arguments)};
  258. diy_select2.prototype={
  259. init:function(opt)
  260. {
  261. this.setOpts(opt);
  262. this.o=this.getByClass(this.opt.TTContainer,document,'div');//容器
  263. this.b=this.getByClass(this.opt.TTDiy_select_btn);//按钮
  264. this.t=this.getByClass(this.opt.TTDiy_select_txt);//显示
  265. this.l=this.getByClass(this.opt.TTDiv_select_list);//列表容器
  266. this.ipt=this.getByClass(this.opt.TTDiy_select_input);//列表容器
  267. this.lengths=this.o.length;
  268. this.showSelect();
  269. },
  270. addClass:function(o,s)//添加class
  271. {
  272. o.className = o.className ? o.className+' '+s:s;
  273. },
  274. removeClass:function(o,st)//删除class
  275. {
  276. var reg=new RegExp('\\b'+st+'\\b');
  277. o.className=o.className ? o.className.replace(reg,''):'';
  278. },
  279. addEvent:function(o,t,fn)//注册事件
  280. {
  281. return o.addEventListener ? o.addEventListener(t,fn,false):o.attachEvent('on'+t,fn);
  282. },
  283. showSelect:function()//显示下拉框列表
  284. {
  285. var This=this;
  286. var iNow=0;
  287. this.addEvent(document,'click',function(){
  288. for(var i=0;i<This.lengths;i++)
  289. {
  290. This.l[i].style.display='none';
  291. }
  292. })
  293. for(var i=0;i<this.lengths;i++)
  294. {
  295. this.l[i].index=this.b[i].index=this.t[i].index=i;
  296. this.t[i].onclick=this.b[i].onclick=function(ev)
  297. {
  298. var e=window.event || ev;
  299. var index=this.index;
  300. This.item=This.l[index].getElementsByTagName('li');
  301. This.l[index].style.display= This.l[index].style.display=='block' ? 'none' :'block';
  302. for(var j=0;j<This.lengths;j++)
  303. {
  304. if(j!=index)
  305. {
  306. This.l[j].style.display='none';
  307. }
  308. }
  309. This.addClick(This.item);
  310. e.stopPropagation ? e.stopPropagation() : (e.cancelBubble=true); //阻止冒泡
  311. }
  312. }
  313. },
  314. addClick:function(o)//点击回调函数
  315. {
  316. if(o.length>0)
  317. {
  318. var This=this;
  319. for(var i=0;i<o.length;i++)
  320. {
  321. o[i].onmouseover=function()
  322. {
  323. This.addClass(this,This.opt.TTFcous);
  324. }
  325. o[i].onmouseout=function()
  326. {
  327. This.removeClass(this,This.opt.TTFcous);
  328. }
  329. o[i].onclick=function()
  330. {
  331. var index = this.parentNode.index;//获得列表
  332. var value = $(this).attr("value");
  333. var name = $(this).attr("name");
  334. var examName = this.innerHTML.replace(/^\s+/,'').replace(/\s+&/,'');
  335. // This.t[index].innerHTML=This.ipt[index].value=this.innerHTML.replace(/^\s+/,'').replace(/\s+&/,'');
  336. This.t[index].innerHTML = examName;
  337. // $("#checkClasses").show();
  338. This.ipt[index].value = value;
  339. This.l[index].style.display='none';
  340. changeGrade(value);
  341. }
  342. }
  343. }
  344. },
  345. getByClass:function(s,p,t)//使用class获取元素
  346. {
  347. var reg=new RegExp('\\b'+s+'\\b');
  348. var aResult=[];
  349. var aElement=(p||document).getElementsByTagName(t || '*');
  350. for(var i=0;i<aElement.length;i++)
  351. {
  352. if(reg.test(aElement[i].className))
  353. {
  354. aResult.push(aElement[i])
  355. }
  356. }
  357. return aResult;
  358. },
  359. setOpts:function(opt) //以下参数可以不设置 //设置参数
  360. {
  361. this.opt={
  362. TTContainer:'diy_select2',//控件的class
  363. TTDiy_select_input:'diy_select_input2',//用于提交表单的class
  364. TTDiy_select_txt:'diy_select_txt2',//diy_select用于显示当前选中内容的容器class
  365. TTDiy_select_btn:'diy_select_btn2',//diy_select的打开按钮
  366. TTDiv_select_list:'diy_select_list2',//要显示的下拉框内容列表class
  367. TTFcous:'focus'//得到焦点时的class
  368. }
  369. for(var a in opt) //赋值 ,请保持正确,没有准确判断的
  370. {
  371. this.opt[a]=opt[a] ? opt[a]:this.opt[a];
  372. }
  373. }
  374. }
  375. var TTDiy_select2=new diy_select2({ //参数可选
  376. TTContainer:'diy_select2',//控件的class
  377. TTDiy_select_input:'diy_select_input2',//用于提交表单的class
  378. TTDiy_select_txt:'diy_select_txt2',//diy_select用于显示当前选中内容的容器class
  379. TTDiy_select_btn:'diy_select_btn2',//diy_select的打开按钮
  380. TTDiv_select_list:'diy_select_list2',//要显示的下拉框内容列表class
  381. TTFcous:'focus'//得到焦点时的class
  382. });//如同时使用多个时请保持各class一致.
  383. });