【发布时间】:2018-02-13 15:45:38
【问题描述】:
我有两个checkbox,取决于checkbox 用户点击哪个,我需要调用其他函数,但是,我无法获取checkbox 标签值。
这是我的代码:
function getLabel(id)
{
return $("#"+id).next().text();
}
function BillStatus(){
console.log("its here");
var label=getLabel('checkboxid1');
console.log(label);
if(label=="No") {
//some function to call here
}else{
//other function to call here
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="check1">
<label>
<input type="checkbox" name="myCheckbox" id="checkboxid1" onclick="BillStatus()" style="visibility: visible"/>
Yes
</label>
</div>
<br>
<div id="check2">
<label>
<input type="checkbox" id="checkboxid2" name="myCheckbox" value="No" onclick="BillStatus()" style="visibility: visible" />
No
</label>
</div>
【问题讨论】:
-
您是否尝试过使用
parent()而不是next()?
标签: javascript jquery html checkbox