首页 新闻 会员 周边

这段jQuery代码怎么精简??

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-10-17 18:53
 1 var title1, titles,
 2         pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\]<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]");
 3         $(".title", h.el)
 4             .focus(function () {
 5                 title1 = $(this).val();//获取修改前的title
 6                 $(this).css('border', '2px solid rgb(38,173,242)');
 7             })
 8             .blur(function () {
 9                 var ids = $(this).parents("li:first").data('id');//获取ID
10                 titles = $(this).val();//获取修改后的title
11                 $(this).css('border', '2px solid #FFF');//隐藏文本框
12                 if (titles == "") {//title不能为空
13                     alert("请输入微课名称!");
14                     $(this).val(title1);
15                     return false;
16                 }
17                 if (pattern.test(titles)) {//非法字符验证
18                     $(this).val(title1);
19                     alert("请不要输入非法字符!");
20                     return false;
21                 }
22                 if (titles == title1) {//如果两个值一样就不需要执行保存方法
23                     return false;
24                 }
25                 jQuery.post(h.vp + 'ajax-smallesson-SmalLessonEdit'
26                     , { id: ids, title: titles }, function (r) {//传递ID和Name两个参数
27                         if (r.code > 0) {
28                             alert('重命名成功!');
29                             title1 = titles;//将title1的值更新为重命名以后的值
30                         }
31                     }, "json");
32                 return false;
33             });
34 
35         /*弹出edit页面*/
36         $(".setting").click(function (el) {
37             debugger;
38             var id = $(this).parents('li:first').data("id");
39             jQuery.post(h.vp + 'ajax-smallesson-edit', { id: id }
40                 , function (r) {
41                     var dlg = _dialog({ title: '微课设置', width: 400, height: 600, }, r, function () {
42                         var title = $(".title_edit").val();//获取微课名称
43                         var Introduction = $('.Introduction_edit').val();//获取微课简介
44                         if (pattern.test(title)) {//非法判断
45                             alert("微课名称包含非法字符!");
46                             return false;
47                         }
48                         if (pattern.test(Introduction)) {
49                             alert("内容简介包含非法字符!");
50                             return false;
51                         }
52                         $('form', dlg).submit();//提交表单
53                         var gradeid = $('.grade_all:checked').map(function () { return $(this).data('id') });
54                         jQuery.post(h.vp + 'ajax-smallesson-Smallesson_Grade_Save'
55                             , { smallId: id, gradeid: gradeid.toArray() }, function (r) {
56                                 //$('#smallesson_form').parents('.ui-dialog-content:first').dialog('close');
57                             }, "json");
58                     }, true);
59                 }, "json");
60             return false;
61         });

简化写法,求大神

梵蒂冈大使的主页 梵蒂冈大使 | 初学一级 | 园豆:2
提问于:2015-09-29 10:24
< >
分享
所有回答(1)
0

别人又看不到你其他部分的代码,简化一般自己做一下就行了啦,太简化的代码易读性下降,也不太好吧

clearbug | 园豆:268 (菜鸟二级) | 2015-09-30 00:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册