简体   繁体   English

获取javascript / JQuery中复选框旁边的文本

[英]get the text next to checkboxes in javascript/JQuery

Is there any way that I can get "Enable Recruiters to directly contact me" in Javascript or JQuery when the checkbox checked? 当复选框选中时,有什么方法可以让Javascript或JQuery中的“让Recruiters直接联系我”?

I know I can get the value easily, but how about the text beside that which can be in a lable? 我知道我可以很容易地获得价值,但是旁边的文字怎么样呢?

<input type="checkbox" name="rec" id="rec" value="ON"><label for='rec'>Enable Recruiters to directly contact me</label>

Please let me know if you need more clarification! 如果您需要更多说明,请告诉我们!

You can bind the change event and use the event source object to call next on it to get the label next to checkbox. 您可以绑定更改事件并使用事件源对象在其旁边调用以获取复选框旁边的标签。

Live Demo 现场演示

$('#rec').change(function(){
   if(this.checked)
    alert($(this).next().text())    
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM