﻿//只能输入数字

jQuery.fn.onlypressnum = function () {
    $(this).css({ imeMode: "disabled", '-moz-user-select': "none" });
    $(this).bind("keypress", function (e) {
        /*alert(e.which);
        $.each(e,function(i,val){
        alert(i "|" val);
        });
        ialert(e.ctrlKey);*/

        //        if (e.ctrlKey == true || e.shiftKey == true)
        //            return false;
 
        if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8)
            return true;
        else if (e.which == 46 && this.value != "")
            return true;
        else if (e.ctrlKey == true && (e.which == 99 || e.which == 118))
            return false;
        else if ((e.ctrlKey == true && (e.which == 43 || e.which == 63)) ||
            (e.ctrlKey == true && (e.which == 56 || e.which == 76))) {
            return true;
        } else {
            return false;
        }
    })
.bind("blur", function () {
    var value = $(this).val();

    if (!(new RegExp("^(?:[+-]?)\\d*\\.?\\d+$").test(value)) && value != "") {
        alert("输入格式不是正确的数值格式，请重新输入。");
        $(this).select();
        $(this).focus();
    }
})
.bind("contextmenu", function () { return false; })
.bind("selectstart", function () { });
//.bind("paste", function () { return false; })
};
