欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery分別獲取選中的復(fù)選框值的示例

 更新時(shí)間:2014年06月17日 10:01:08   投稿:whsnow  
這篇文章主要介紹了jQuery如何分別獲取選中的復(fù)選框值,需要的朋友可以參考下
復(fù)制代碼 代碼如下:

function jqchk(){ //jquery獲取復(fù)選框值
var s='';
$('input[name="aihao"]:checked').each(function(){
s+=$(this).val()+',';
});

點(diǎn)擊“提交”后,可以得到正確的選擇值了,但是后面多一個(gè),(英文逗號(hào)),這個(gè)可以檢測(cè)一下再用substring去除,或者獲取到復(fù)選框選擇值后一般都要轉(zhuǎn)成數(shù)組再使用的,所以也可以在轉(zhuǎn)成數(shù)組后,去除最后一個(gè)數(shù)組元素。
復(fù)制代碼 代碼如下:

if (s.length > 0) {
//得到選中的checkbox值序列
s = s.substring(0,s.length - 1);
}
alert(s==''?'你還沒(méi)有選擇任何內(nèi)容!':s);
}
</script>

直接上代碼,主要是獲取checkbox值的方法:將其放到數(shù)組中,然后連接成字符串
復(fù)制代碼 代碼如下:

var chenked=$("input[type='checkbox']:checked").val([]);
var names = "";
for(var i=0;i<chenked.length;i++){
names += chenked[i].value +",";
}

可以更優(yōu)雅一些:
復(fù)制代碼 代碼如下:

var arr_v = new Array();

=$("input[type='checkbox']:checked").each(function(){

arr_v.push(this.val());

});

arr_v.join(',');

即可以了
復(fù)制代碼 代碼如下:

//此為重點(diǎn),該句與下面的第一句效果一樣
var selectedItems = new Array();
$("input[@name='itemSelect[]']:checked").each(function() {selectedItems.push($(this).val());});

if (selectedItems .length == 0)
alert("Please select item(s) to delete.");
else
$.ajax({
type: "POST",
url: "/ajax_do_something.php",
data: "items=" + selectedItems.join('|'),
dataType: "text",
success: function (request) {
document.location.reload();
},
error: function(request,error){
alert('Error deleting item(s), try again later.');
}
}
);

java 拆分
復(fù)制代碼 代碼如下:

String names = null;
String name1 = null;
String name2 = null;
names = request.getParameter("names");
String[] name = names.split(",");
for(String x : name){
if("zhangsan".equals(x)){
name1 = x;
}
if("lisi".equals(x)){
name2 = x;
}
}

jquery 修改時(shí)候選中 后臺(tái)查詢的復(fù)選框
復(fù)制代碼 代碼如下:

var struids='${useridstr}'; //后臺(tái)獲取數(shù)據(jù)
alert(struids);
if(struids!='')
{
var str=struids.split(",");
for(var j=0;j<str.length;j++)
{
$(":checkbox[value='"+str[j]+"']").attr("checked",true);
}
}


下拉框
復(fù)制代碼 代碼如下:

var module='${module}'
$("#module option[value='" + module + "']").attr("selected","selected");

var s = $("#parentId").find("option:selected").val();

相關(guān)文章

最新評(píng)論