茗洋芳竹的收藏与问题的解决方案的专题[一]

2013年7月6日17:14:33

 

$('#com').combobox('getValue')获取当前选中的值
$('#com').combobox('getText')获取当前选中的文字

 

 

最新添加

tree根据节点,获取子元素

var _childrens = $(树的id).tree('getChildren', node.target);

 

拓展,只获得一级子元素

  1. $.extend($.fn.tree.methods,{
  2.         getLeafChildren:function(jq, params){
  3.                 var nodes = [];
  4.                 $(params).next().children().children("div.tree-node").each(function(){
  5.                         nodes.push($(jq[0]).tree('getNode',this));
  6.                 });
  7.                 return nodes;
  8.         }
  9. });

基本操作例子

   function InitTree() {
        $('#SubEmployeeList').tree({
            url: '/Common/GetSubordinateTree',
            width: 200,
            valueField: 'id',
            textField: 'text',
            checkbox: false,
            cascadeCheck: false,
            animate: false,
            lines: false,
            onlyLeafCheck: true,
            onClick: function (node) {
                //判断是不是根节点
                if (node.id != -1) {
                    $("#EmployeeIds").val(node.id);
                    searchData();
                } else {
                    var _childrens = $('#SubEmployeeList').tree('getChildren', node.target);
                    var empid = "";
                    if (_childrens && _childrens.length > 0) {
                        for (var i = 0; i < _childrens.length; i++) {
                            if (_childrens[i].id != "-1") {
                                empid += _childrens[i].id + ",";
                            }
                        }
                        empid = empid.substr(0, empid.length - 1);
                        $("#EmployeeIds").val(empid);
                        searchData();
                    } else {
                        alert("该节点下没有任何人,无需查询")
                    }
                }
            },
            onBeforeLoad: function (node, param) {
                $.messager.progress();
            },
            onLoadSuccess: function (node, param) {
                var c = $(window).height(); //浏览器时下窗口文档对于象宽度
                $("#employeeTree").height(c - 34);
                $(window).resize(function () {
                    tabResize();
                });
                $.messager.progress('close');

            }
        });
    }

 

 

 

 

 

 

datagrid各行换色

 

rowStyler: function (rowIndex, rowData) {
if (rowIndex % 2 == 1)
return 'background-color:#F6F6F6;';
},

 

 

 

 

 

 

 

 

 

 

 

 

一、自己总结的问题解决记录

1.将一个JSON对象转换成字符串

 var O2String = function (O) {
        //return JSON.stringify(jsonobj);

        var S = [];
        var J = "";
        if (Object.prototype.toString.apply(O) === '[object Array]') {
            for (var i = 0; i < O.length; i++)
                S.push(O2String(O[i]));
            J = '[' + S.join(',') + ']';
        }
        else if (Object.prototype.toString.apply(O) === '[object Date]') {
            J = "new Date(" + O.getTime() + ")";
        }
        else if (Object.prototype.toString.apply(O) === '[object RegExp]' || Object.prototype.toString.apply(O) === '[object Function]') {
            J = O.toString();
        }
        else if (Object.prototype.toString.apply(O) === '[object Object]') {
            for (var i in O) {
                O[i] = typeof (O[i]) == 'string' ? '"' + O[i] + '"' : (typeof (O[i]) === 'object' ? O2String(O[i]) : O[i]);
                S.push(i + ':' + O[i]);
            }
            J = '{' + S.join(',') + '}';
        }

        return J;
    };

 

 

 

 

2.easy-ui中 下拉框禁止输入文字

行内这样写:

data-options="editable:false"

 

动态生成的设置一下editable

 

  $(tempId).combobox({
            url: '/Common/GetCurrentType',
            width: 150,
            required: true,
            valueField: 'id',
            textField: 'text',
            onSelect: function (rec) {
                companyOp.change(tempKey);
            },
            onLoadSuccess: function () {

                var data = $(this).combobox('getData'); //获得成功后的json数据,然后附上第一项的值
                if (data.length > 0) {
                 $(this).combobox('select',data[0].id);  //这里不要是显示的文本,因为你post的时候,提交的会是value值,同样,他也会选中你想要的值
                }
          
            }
        });

 

 

3. 在easyui的gridview中显示的内容想换行,一种当时保存数据的时候

后台C#用 Environment.NewLine作为字符串的换行符号,则显示的时候,会是换行的

 

4.在view中,如果你是table布局,在一个td中,例如 Model.备注信息,显示在一行,没有换行的时候,在table中,加一个样式,<table style="word-break:break-all">...</table>,就可以换行了

 

5.关于ASP.NET MVC中获得表单中查询条件的内容,然后post过去

表单采用这种形式

  @using (Html.BeginForm("List", "Recycle", FormMethod.Post, new { @Name = "ff", @Id = "ff" }))
            {
                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="adm_8">
            ...

}

  //获取表单数据
    function getPostData() {
        var data = $("#ff").serialize();
        return $('#ff').attr('action') + '?' + data;
    }

 

6.读取config文件

 

xml文件如下:

还有取config的方法

ConfigurationManager.AppSettings["TextColor"].ToString();  

 7.jquery最大化浏览器窗口

  1. <script type="text/javascript">  
  2.   
  3. $(document).ready(function(){     //使用jquery的ready方法似的加载运行  
  4. if (window.screen) {              //判断浏览器是否支持window.screen判断浏览器是否支持screen  
  5.     var myw = screen.availWidth;   //定义一个myw,接受到当前全屏的宽  
  6.     var myh = screen.availHeight;  //定义一个myw,接受到当前全屏的高  
  7.     window.moveTo(00);           //把window放在左上脚  
  8.     window.resizeTo(myw, myh);     //把当前窗体的长宽跳转为myw和myh  
  9.     }  
  10. });  
  11.   
  12. </script>  

 8. 关于后台string个属性,里面含有换行,但是页面是不换行的解决办法:

        public string FirstMoneyShow
        {
            get
            {
                return Math.Round(FirstMoney, 2).ToString() + Environment.NewLine + ((CurrencyType)Currency).GetDescription();
            }
        }

  @Html.Raw(Model.FirstMoneyShow.Replace("\r\n","<br>"))

  前台获得值后,用js的手段,换行

  这是EasyUI中grid中某列的格式化语句

 function MoneyFormatter(value, row, index) {
      return value.replace("\r\n","<br/>");

    }

 由于分辨率大小有限,在列表中,日期显示不完了,有时自动换行,影响美观,所以决定年月日,时分秒换行显示

  public System.DateTime? PayTime
        {
            get;
            set;
        }
        public string PayTimeShow
        {
            get {
                if (PayTime.HasValue)
                {
                    return ((DateTime)PayTime).ToString("yyyy-MM-dd HH:mm:ss");
                }
                return "";
            }
        }

前台js的写法:

  function CustomDateFormatter(value, row, index) {
      return value.replace(" ","<br/>");
  }

 

9. js抖动一个div,例如登陆窗口,为输入用户名和密码,点了登陆

jQuery.fn.shake = function(times,offset,delay) {//次数,偏移,间隔
02 this.stop().each(function() {
03     var Obj = $(this);
04     var marginLeft = parseInt(Obj.css('margin-left'));
05     var delay = delay > 20 ? delay : 20;
06     Obj.animate({'margin-left':marginLeft+offset},delay,function(){
07         Obj.animate({'margin-left':marginLeft},delay,function(){
08             times = times - 1;
09             if(times > 0)
10             Obj.shake(times,offset,delay);
11             })
12         });
13  
14     });
15     return this;
16 }
17
18 //示例:$('.wrap').shake(4,4,100);​
19 //演示地址:http://runjs.cn/detail/hb1zsvl5

 

 10.一个简单的图文混编

<div style="height: 300px; width: 100%"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: left; padding-top: 0px; padding-left: 0px; margin: 0px 15px 0px 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="$image_thumb.png" width="225" height="160" />我我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填我在填在填</div>

 

 

11.关于my97 datepicker的两个日期作为时间段查询,在ASP.NET MVC中使用

    前面的一个日期,最大时间为当天,后面的一个日期,最小日期为前面一个日期,最大日期为当天

           @Html.TextBoxFor(m => m.CreateTime, new { @class = "Wdate adm_21", @onclick = @"WdatePicker({dateFmt:'yyyy年MM月dd日',skin:'blue',maxDate:'%y-%M-%d'})" }) &nbsp;至&nbsp;
           @Html.TextBoxFor(m => m.ApplicantTime, new { @class = "Wdate adm_21", @onclick = @"WdatePicker({dateFmt:'yyyy年MM月dd日',skin:'blue',minDate:'#F{$dp.$D(\'CreateTime\')}',maxDate:'%y-%M-%d'})" })

 

 

 12. 有时自动调整页面高度和宽度,需要知道浏览器的宽度高度等

<script type="text/javascript"> 
$(document).ready(function() 
{ 
alert($(window).height()); //浏览器时下窗口可视区域高度 
alert($(document).height()); //浏览器时下窗口文档的高度 
alert($(document.body).height());//浏览器时下窗口文档body的高度 
alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin 
alert($(window).width()); //浏览器时下窗口可视区域宽度 
alert($(document).width());//浏览器时下窗口文档对于象宽度 
alert($(document.body).width());//浏览器时下窗口文档body的高度 
alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin 
} 
) 
</script>

 

 13.拓展easyUI 表单中的 验证器

 $.extend($.fn.validatebox.defaults.rules, {
        positive_int: {

            validator: function (value, param) {

                if (value) {

                    return /^\d+$/.test(value);

                } else {


                }

            },

            message: '只能输入大于等于0的正数.'

        }
    });

 

用的时候:

@Html.TextBoxFor(a => a.ExpressFee, new { @class = "easyui-validatebox 其他样式", required = true, @validType = "positive_int" })

 

 14.关于MVC中 Radio的问题

自己写HTML,如果选中发短信,短信内容不能为空,否,就可以为空的验证

例如:
<tr>

<td height="32" class="adm_45" align="right">
                            发送短信&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            @Html.HiddenFor(x => x.ExpressMobile)
                        </td>
                        <td class="adm_42" align="left">
                            &nbsp;&nbsp;<input type="radio" id="SendMessage" name="SendMessage" value="true" />是
                            &nbsp;&nbsp;&nbsp;
                            <input type="radio" id="SendMessages" name="SendMessage" value="false" checked="checked" />否
                        </td>

  </tr>
                    <tr>
                        <td height="32" class="adm_45" align="right">
                            短信内容&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </td>
                        <td class="adm_42" align="left">
                            &nbsp;&nbsp;@Html.TextAreaFor(s => s.Messag, new { rows = 3, @style = "width: 90%;word-break:break-all;" })
                        </td>
                    </tr>

获得值开始验证:

 var c = $('input[name="SendMessage"]:checked').val() == 'true' && $("#Messag").val().length == 0;
        if (c) {
            $.messager.alert('操作提示', '请输入短信内容!', 'info', function () {
                $("#Messag").focus();
                return;
            });
        }

    if ($('input[name="SendMessage"]:checked').val() != 'true' || ($('input[name="SendMessage"]:checked').val() == 'true' && $("#Messag").val().length > 0)) {
            if ($('#ffddf').form("validate")) {
                $.messager.progress();
                $.ajax({
                    type: "post",
                    url: "/Trace/SubmitSendInfo",
                    data: getContent(),
                    success: function (data) {
                        if (data.IsSuccess) {
                            $.messager.alert('成功', '操作成功!', 'info', function () {
                                parent.closeTab('close');
                            });
                        } else {
                            $.messager.alert('失败', data.Message, 'error');
                        }
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        $.messager.alert('失败', '错误代码:' + jqXHR.status, 'error');
                    }
                });
                $.messager.progress('close'); // hide progress bar while submit successfully
            }
        }

 页面加载时候,jQuery默认设置选中:

      $("#rdoToday").attr("checked",'checked');

change事件:

$("input:radio").change(
          function () {
              var d = $('input[name="ChooseDate"]:checked').val();
            //  $("#TimeDateType").val(d);  //隐藏字段,用于提交到后台,到底哪个被选中了
              if (d == 4) {
                  $("#titleDate").show();
              } else {
                  $("#titleDate").hide();
               
              }
          }
        );

    $(function () {
        $("#rdoToday").attr("checked",'checked'); //默认选中
        Init();
        $("#rdoToday").change();  //触发选中
    });

 

 

15.每次时间段查询,取的开始时间00:00:00,结束时间23:59:59,写个扩展方法直接用
        /// <summary>
        /// 获取开始时间
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTime GetBeginTime(this DateTime dateTime)
        {
            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0);
        }
        /// <summary>
        /// 获取结束时间
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTime GetEndTime(this DateTime dateTime)
        {
            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 23, 59, 59);
        }
        /// <summary>
        /// 获取开始时间
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTime? GetBeginTime(this DateTime? dateTime) {
            if (!dateTime.HasValue)
            {
                return dateTime;
            }
            return new Nullable<DateTime>(dateTime.Value.GetBeginTime());
        }
        /// <summary>
        /// 获取结束时间
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTime? GetEndTime(this DateTime? dateTime)
        {
            if (!dateTime.HasValue)
            {
                return dateTime;
            }
            return new Nullable<DateTime>(dateTime.Value.GetEndTime());
        }

 用js获得月底的日期,比如当天是2013年5月8日,那么该返回31

//JS获得月底时间
    function getLastDay(year, month) {
        var new_year = year;    //取当前的年份        
        var new_month = month++; //取下一个月的第一天,方便计算(最后一天不固定)        
        if (month > 12)            //如果当前大于12月,则年份转到下一年        
        {
            new_month -= 12;        //月份减        
            new_year++;            //年份增        
        }
        var new_date = new Date(new_year, new_month, 1);                //取当年当月中的第一天        
        var date_count = (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate(); //获取当月的天数      
        var last_date = new Date(new_date.getTime() - 1000 * 60 * 60 * 24); //获得当月最后一天的日期
        return date_count;
    }    

 

使用:  var last = getLastDay(new Date().getYear(), new Date().getMonth()+1);

 JS可以像C#那样格式化日期Date

//--------------------------------------------------- 
// 日期格式化 
// 格式 YYYY/yyyy/YY/yy 表示年份 
// MM/M 月份 
// W/w 星期 
// dd/DD/d/D 日期 
// hh/HH/h/H 时间 
// mm/m 分钟 
// ss/SS/s/S 秒 
//--------------------------------------------------- 
Date.prototype.Format = function (formatStr) {
    var str = formatStr;
    var Week = ['日', '一', '二', '三', '四', '五', '六'];

    str = str.replace(/yyyy|YYYY/, this.getFullYear());
    str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));

    str = str.replace(/MM/, this.getMonth() > 9 ? (this.getMonth() + 1).toString() : '0' + (this.getMonth() + 1));
    str = str.replace(/M/g, (this.getMonth() + 1));

    str = str.replace(/w|W/g, Week[this.getDay()]);

    str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
    str = str.replace(/d|D/g, this.getDate());

    str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
    str = str.replace(/h|H/g, this.getHours());
    str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
    str = str.replace(/m/g, this.getMinutes());

    str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
    str = str.replace(/s|S/g, this.getSeconds());

    return str;
}

使用:   $("#WorkTimeEnd").val(new Date().Format("yyyy年MM月dd日"));

例如最后一天的值获得了是 last

   $("#WorkTimeEnd").val(new Date().Format("yyyy年MM月" + last + "日"));

当月1日:

   $("#WorkTimeEnd").val(new Date().Format("yyyy年MM月01日"));

这样在做软件的时候,根据当月1日到月底的一个报表条件就搞好了

 

 

 

 16.easy UI tree单选树,父节点不可选,还有一点问题

   var lastNode;
    function InitTree() {
        $('#SubEmployeeList').tree({
            url: '/Common/GetSubordinateTree',
            width: 200,
            valueField: 'id',
            textField: 'text',
            checkbox: true,
            cascadeCheck: false,
            animate: false,
            lines: false,
            onlyLeafCheck: true,
            onCheck: function (node, checked) {
                //                var nodes = $('#SubEmployeeList').tree('getChecked');
                if (lastNode) {
                    if (node != lastNode) {  //跟原来一样就不管
                        //如果不一样,先取消上次节点的选择
                        $('#SubEmployeeList').tree('uncheck', lastNode.target);
                        $("#EmployeeId").val(node.id);
                        lastNode = node;
                    } else {
                        alert("跟上次一样");
                    }

                } else { //第一次单击直接赋值
                    $("#EmployeeId").val(node.id);
                    lastNode = node;

                }

            }
        });
    }

 

另一种思路:使用select

function InitTree() {
        $('#SubEmployeeList').tree({
            url: '/Common/GetSubordinateTree',
            width: 200,
            valueField: 'id',
            textField: 'text',
            checkbox: false,
            cascadeCheck: false,
            animate: false,
            lines: false,
            onlyLeafCheck: true,
            onClick: function (node) {
                //判断是不是根节点
                if (node.id != -1) {
                    $("#EmployeeId").val(node.id); //树上选中元素的id
                    //然后开始查数据

                }
            }
        });
    }

 

 

 17.string的拓展方法,长度达到一定长度需要省略的一个扩展方法

     public static class ExtensionStr
    {
        /// <summary>
        /// 对字符串截取一定的长度,超过这个长度,加省略号
        /// </summary>
        /// <param name="str">要处理的字符串</param>
        /// <param name="length">长度</param>
        /// <returns></returns>
        public static string ReturnCutString(this string str, int length)
        {
            string res = "";
            if (str.Length > length)
                res = str.Substring(0, length) + "...";//从0开始,后面省略号可不要
            else
                res = str;//如果小于等于length位,则不变
            return res;
        }
    }

 

使用

  public string PlanSummaryShow
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(PlanSummary))
                {
                    return this.PlanSummary.ReturnCutString(80);
                }
                else
                {
                    return "";
                }
            }
        }

 

 

18.Easy UI进度条的使用,在添加数据的时候

     function SubmitSend() {
        if ($('#ffddf').form("validate")) {
      
            $.ajax({
                type: "post",
                url: "/WorkPlan/WorkPlansAdd",
                data: getContent(),
                beforeSend: function (data) {
                    $.messager.progress();
                },
                complete: function (jqXHR, textStatus, errorThrown) {
                    $.messager.progress('close'); // hide progress bar while submit successfully
                },
                success: function (data) {
                  .....

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $.messager.alert('失败', '错误代码:' + jqXHR.status, 'error');
                }
            });
         
        } 

 

也就是加上这两行代码:

               beforeSend: function (data) {
                    $.messager.progress();
                },
                complete: function (jqXHR, textStatus, errorThrown) {
                    $.messager.progress('close'); // hide progress bar while submit successfully
                },

table中单元格,显示数据的时候,如果Model点属性,没有值,那么td的高会有问题,与其他的td高度不一样

      例如可以这样写  <td style="minheight:20px;height:20px">

 

 在网页中加上音效

<audio autoplay="autoplay" loop="loop">
<source src="music/雨.mp3">
</audio>

 

19.JS获得月底时间

//JS获得月底时间
function getLastDay(year, month) {
var new_year = year; //取当前的年份
var new_month = month++; //取下一个月的第一天,方便计算(最后一天不固定)
if (month > 12) //如果当前大于12月,则年份转到下一年
{
new_month -= 12; //月份减
new_year++; //年份增
}
var new_date = new Date(new_year, new_month, 1); //取当年当月中的第一天
var date_count = (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate(); //获取当月的天数
var last_date = new Date(new_date.getTime() - 1000 * 60 * 60 * 24); //获得当月最后一天的日期
return date_count;
}

 

使用

var last = getLastDay(new Date().getYear(), new Date().getMonth() + 1);
$("#WorkTimeEnd").val(new Date().Format("yyyy年MM月" + last + "日"));

 

 

 

二、 开发之前的一些疑问解决办法:

1.如果没有按照正常的先装iis后装.net的顺序,可以使用此命令重新注册一下:
32位的Windows:
---------------------------------------------------------------------------
1. 运行->cmd

2. cd  C:\Windows\Microsoft.NET\Framework\v4.0.30319

3. aspnet_regiis.exe -i

 

64位的Windows:
---------------------------------------------------------------------------
1. 运行->cmd

2. cd  C:\Windows\Microsoft.NET\Framework64\v4.0.30319

3. aspnet_regiis.exe -i

 

 

三、 学历提升说明 链接地址

合肥自考报名:http://zk.ah163.net/index.php

合肥自考报名流程图:http://www.hfzk.net.cn/portal/upload/003005001/812/201271384434509.htm

微软认证官网 http://www.microsoft.com/china/learning/

Adobe认证考试机构 http://baike.baidu.com/view/1253991.htm

安徽合肥2013年4月自考报名安排(参考以前的) http://www.zikao365.com/new/201211/li2012111509222595652912.shtml

安徽省高等教育自学考试2012年10月课程考试时间安排表 http://www.zikao365.com/new/201205/li2012050809400945499073.shtml

专科

本科

 

posted @ 2013-04-28 09:54  AYUI框架  阅读(981)  评论(5编辑  收藏  举报