富强民主文明和谐 点击事件变颜色

需要引入jquery

 <script type="text/javascript"> 
var a_idx = 0; 
jQuery(document).ready(function($) { 
    $("body").click(function(e) { 
        var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正" ,"法治", "爱国", "敬业", "诚信", "友善"); 
        var b = new Array("red","blue","yellow","green","pink","blue","orange");
        var $i = $("<span/>").text(a[a_idx]); 
        a_idx = (a_idx + 1) % a.length; 
        b_idx = (a_idx+1)%7;/* 七中颜色变色 */
        var x = e.pageX, 
        y = e.pageY; 
        $i.css({ 
            "z-index": 9999, 
            "top": y - 20, 
            "left": x, 
            "position": "absolute", 
            "font-weight": "bold", 
            "color": b[b_idx]
        }); 
        $("body").append($i); 
        $i.animate({ 
            "top": y - 180, 
            "opacity": 0 
        }, 
        1500, 
        function() { 
            $i.remove(); 
        }); 
    }); 
}); 
</script>

解决validate无法验证多个相同name的input

解决validate无法验证多个相同name的input (动态生成的表格)

记录实际业务遇到问题

首先给input分别设置不同的id

//用于生成uuid
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }

    function guid() {
        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
    }
//为动态添加的元素绑定事件
    $('#contentTable').on('click', '.addTable', function () {
        // var uuid = "qty" + guid();
        //步骤预设
        var str1 = ' <tr>\n' +
            '                                <td>\n' +
            '                                    <input id="qty' + guid() + '" type="text" style="width: 126px;height: 32px" class="input-xlarge required"\n'
            +
            '                                           name="gspStepTaskPresetChildtable.stepName"></input>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input id="qty' + guid() + '" type="text" style="width: 126px;height: 32px" class="input-xlarge required"\n'
            +
            '                                           name="gspStepTaskPresetChildtable.workContent"></input>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input id="qty' + guid() + '"  type="text" style="width: 126px;height: 32px" class="input-xlarge required"\n'
            +
            '                                       onkeyup="value=value.replace(/[^\\d\\.]/g,\'\')"     name="gspStepTaskPresetChildtable.completeDays"></input>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input  id="qty' + guid() + '" type="text" style="width: 126px;height: 32px" class="input-xlarge required"\n'
            +
            '                                           name="gspStepTaskPresetChildtable.milestone"></input>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input id="qty' + guid() + '" type="text" style="width: 126px;height: 32px" class="input-xlarge required"\n'
            +
            '                                           name="gspStepTaskPresetChildtable.precautions"></input>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input id="qty' + guid() + '" type="text" style="width: 126px;height: 32px" class="input-xlarge required"\n'
            +
            '                                      onkeyup="value=value.replace(/[^\\d\\.]/g,\'\')"      name="gspStepTaskPresetChildtable.standardWorkingHours"></input>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                   <p class="addTable">+</p>\n' +
            '                                   <p class="delTable" onclick="delTable(this);">-</p>\n' +
            '                                </td>\n' +
            '                            </tr>';

        $('#contentTable > tbody:nth-child(2)').append(str1);

    });

设置validate的多个input验证方法为根据id验证

$(function () {
        if ($.validator) {
            $.validator.prototype.elements = function () {
                var validator = this,
                    rulesCache = {};
                return $([]).add(this.currentForm.elements)
                    .filter(":input")
                    .not(":submit, :reset, :image, [disabled]")
                    .not(this.settings.ignore)
                    .filter(function () {
                        var elementIdentification = this.id || this.name;
                        !elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
                        if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
                            return false;
                        rulesCache[elementIdentification] = true;
                        return true;
                    });
            };

        }
        # [id^=qty] 根据实际业务需求修改 id以qty开头的
        $('[id^=qty]').each(function (e) {
            $(this).rules('add', {
                minlength: 2,
                required: true
            })
        });
    });

    

js判断值是否在字符串中

js判断值是否在字符串中 可用于select2多选值判断

$("#targetType").val().toString().search("7") == -1  不存在

$("#targetType").val().toString().search("7") != -1   存在

Spring的ioc和aop

AOP:
主要的功能是:日志记录,性能统计,安全控制,事务处理,异常处理等等。
把就是那些与业务无关,但是被业务系统相互调用的代码封装起来,便于减少系统的重复代码,降低模块间的耦合度,并有利于未来的可操作性和可维护性。

IOC:
由spring来负责控制对象的生命周期和对象之间的关系。
在系统运行中,动态的向某个对象提供它需要的对象,然后在巴拉巴拉讲讲以前都是手动注入对象等等等。。。

二、IOC的好处

  可维护性比较好,非常便于进行单元测试,便于调试程序和诊断故障。代码中的每一个Class都可以单独测试,彼此之间互不影响,只要保证自身的功能无误即可,这就是组件之间低耦合或者无耦合带来的好处。

  每个开发团队的成员都只需要关心实现自身的业务逻辑,完全不用去关心其它的人工作进展,因为你的任务跟别人没有任何关系,你的任务可以单独测试,你的任务也不用依赖于别人的组件,再也不用扯不清责任了。

  可复用性好,我们可以把具有普遍性的常用组件独立出来,反复利用到项目中的其它部分,或者是其它项目,当然这也是面向对象的基本特征。

  IOC生成对象的方式转为外置方式,也就是把对象生成放在配置文件里进行定义,这样,当我们更换一个实现子类将会变得很简单,只要修改配置文件就可以了,完全具有热插拨的特性。

如何去掉/转换数字/金额分位符

将一个数字转换为有千分位的格式:

    NumberFormat numberFormat1 = NumberFormat.getNumberInstance();  
    System.out.println(numberFormat1.format(11122.33)); //结果是11,122.33  
      
    NumberFormat numberFormat2 = NumberFormat.getNumberInstance();  
    numberFormat2.setGroupingUsed(false); //设置了以后不会有千分位,如果不设置,默认是有的  
    System.out.println(numberFormat2.format(11122.33)); //结果是11122.33   

将一个数字转换为有千分位的格式:

    String amount1 = "13,000.00";  
    double d1 = new DecimalFormat().parse(amount1).doubleValue(); //这里使用的是parse,不是format  
    System.out.println(String.valueOf(d1)); //结果是13000.00