<p>[颜色]:<input value="140,1800" name="spec_15" type="radio">无色[1800]
<input value="141,1800" name="spec_15" type="radio">红色[1800]
<input checked="checked" value="142,1800" name="spec_15" type="radio">白色[1800]</p>如上一段HTML,第三个radio处于选中状态,使用jquery获取得到结果:
[颜色]:白色[+1800]如果是第二个radio处于选中状态即得到结果:
[颜色]:红色[+1800]....如果第N个radio处于选中状态,得到
[颜色]:与N结尾相连的一段文本"[颜色]:"不是写死的可能废话了^_^,大家帮帮忙.
function test(){
return '[颜色]:' + $('p>input:checked')[0].nextSibling.nodeValue.replace('[', '[+');
}
<head>
<title>ceshi</title>
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
$(document).ready( function() {
alert($("input[@type='radio'][@name='spec_15'][@checked]").get(0).nextSibling.nodeValue); $("input[@type='radio'][@name='spec_15']").each(function(){
$(this).click(function(){
if( $(this).attr("checked")==true){
alert($(this).get(0).nextSibling.nodeValue);
}
});
});
});
</script>
</head>
<body><p>[颜色]:
<input value="140,1800" name="spec_15" type="radio">无色[1800]
<input value="141,1800" name="spec_15" type="radio">红色[1800]
<input checked="checked" value="142,1800" name="spec_15" type="radio">白色[1800]
</p></body>
</html>
你如果要得到后面的值有简单的方法 把这个值附给input的一个属性 比如title 用jquery 的 attr方法得到
如果来个循环,每个<p></p>标签内的内容都不一样,我还要给每个取出来的值加不同的类似于"[XX]:"的前缀?
所以[颜色]最好也是读出来的.
alert($("p").get(0).childNodes[0].nodeValue+$("p input[checked=true]").get(0).nextSibling.nodeValue);