获取指定表单的所有表单域的值,形成一个字符串,方便Get提交

function GetPara() {

var parameters = "?t=" + Math.random();  //加随机数,避免缓存
$("#search input").each(function () {
if (($(this).attr("type") == "text" || $(this).attr("type") == "password" || $(this).attr("type") == "hidden") && $(this).attr("name") != "page") {//文本框,密码框,隐藏域,页码除外
parameters += "&" + $(this).attr("name") + "=" + encodeURI($.trim($(this).val()));
} else if ($(this).attr("type") == "radio") {//单选框参数
if (parameters.indexOf("&" + $(this).attr("name")) < 0) {
parameters += "&" + $(this).attr("name") + "=" + $("#search input:radio[name='" + $(this).attr("name") + "']:checked").val();
}
} else if ($(this).attr("type") == "checkbox") {//复选框参数
var temp = false;
if ($(this).attr("checked") == "checked") {
temp = encodeURI($.trim($(this).val()));
}
parameters += "&" + $(this).attr("name") + "=" + temp;
}
});

$("#search select").each(function () { //下拉框
parameters += "&" + $(this).attr("name") + "=" + encodeURI($.trim($(this).val()));
});
$("#search textarea").each(function () { //文本域的参数
parameters += "&" + $(this).attr("name") + "=" + encodeURI($.trim($(this).val()));
});

$("#search input[name='page']").each(function () { //页码放在最后
parameters += "&" + $(this).attr("name") + "=" + encodeURI($.trim($(this).val()));
});
return parameters;
}

posted @ 2012-02-24 17:26  第7笔画  阅读(331)  评论(0编辑  收藏  举报