2014-03-06 55 views
0

當複選框被選中時,是否有任何方法可以讓我在Javascript或JQuery中使用「允許Recruiters直接與我聯繫」?獲取javascript/jQuery中複選框旁邊的文本

我知道我可以很容易地得到它的價值,但那些可以在標籤旁邊的文字怎麼樣?

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

請讓我知道,如果你需要更多的澄清!

回答

2

您可以綁定change事件並使用事件源對象調用next對象以獲取複選框旁邊的標籤。

Live Demo

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