js checkbox 获取选中项 属性 非 value
<inputprice="28.99"name="accessories"value="hua(+$28.99)"id="attr97"type="checkbox"><...
<input price="28.99" name="accessories" value="hua (+$28.99)" id="attr97" type="checkbox">
<input price="35.99" name="accessories" value="hudie (+$35.99)" id="attr98" type="checkbox">
... ... 此处省略很多个input
<script>
var str=document.getElementsByName("accessories");
var objarray=str.length;
var accessoriesa = "";
var accessoriesb = "";
for (i=0;i<objarray;i++){
if(str[i].checked == true) {
accessoriesa+=str[i].value+" ";
accessoriesb+=str[i].attr("price")+"|";
}
}
if(accessoriesa == "") { var accessories = ""; } else { var accessories = "\n" + "Accessories: " + accessoriesa; }
if(accessoriesb == "") { var accessoriesprice = ""; } else { var accessoriesprice = accessoriesb; }
</script>
这样写是错的,不能获取 price 的值, 只能获取 value 的值。怎么才能获取到选中的checkbox的price值? 展开
<input price="35.99" name="accessories" value="hudie (+$35.99)" id="attr98" type="checkbox">
... ... 此处省略很多个input
<script>
var str=document.getElementsByName("accessories");
var objarray=str.length;
var accessoriesa = "";
var accessoriesb = "";
for (i=0;i<objarray;i++){
if(str[i].checked == true) {
accessoriesa+=str[i].value+" ";
accessoriesb+=str[i].attr("price")+"|";
}
}
if(accessoriesa == "") { var accessories = ""; } else { var accessories = "\n" + "Accessories: " + accessoriesa; }
if(accessoriesb == "") { var accessoriesprice = ""; } else { var accessoriesprice = accessoriesb; }
</script>
这样写是错的,不能获取 price 的值, 只能获取 value 的值。怎么才能获取到选中的checkbox的price值? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询