将数字转成货币字符串 ¥123,456,7.00

function setCurrency(num) {
	if(isNaN(num)) return '';
	num = parseFloat(num);
    var sign = '';
    var s;
    if (num < 0) {
        sign = '-';
        num *= -1;
    }
    s = num.toFixed(2).toString();
    s = s.replace(".", ",");
    var re = /(\d)(\d{3},)/;
    while (re.test(s))
        s = s.replace(re, "$1,$2");
    s = s.replace(/,(\d\d)$/, ".$1");
    return sign + '¥' + s.replace(/^\./, "0.");
}

function currencyValue(str) {
    var num = parseFloat(str.replace(/[,¥]/g, ''));
    if (isNaN(num))
        num = 0;
    return num;
}

FireFox下jQuery UI Autocomplete在中文输入下的Bug

FireFox下jQuery UI Autocomplete在中文输入下的Bug,主要原因是中文輸入時不會觸發原本在autocomplete 榜定的keydown事件。

//fixed firefox and ie in IME bug 
$('#input_id').bind("input.autocomplete", function(){ 
    $(this).trigger('keydown.autocomplete'); 
});

转自:http://groups.google.com/group/jquery-/browse_thread/thread/8f34129edc5da55e

jquery 获取 url 参数

方法如下:

function getUrlParam(name){
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r!=null)
        return unescape(r[2]); //返回参数值
    return null;
}