如何使用javascript获取下一个标签名称旁边的复选框 [英] How to get checkbox next to next label name using javascript

查看:75
本文介绍了如何使用javascript获取下一个标签名称旁边的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



@ Html.CheckBoxFor(m => m.isWeekday,new {id =dayId})

< label> 某个图标<标签>

< label for =weekDay>星期日< / label>


@Html.CheckBoxFor(m => m.isWeekday, new { id = "dayId"})
<label>some icon<label>
<label for="weekDay">Sunday</label>





如何使用jquery获取复选框旁边的工作日标签的标签值



复选框是检查我想得到标签的文字,即星期日

我们如何获得标签文本



How to get the label value of weekday label which next by next to checkbox using jquery

when the check box is checked i want to get the text of the label i.e "Sunday"
How can we get the label text

推荐答案

使用jQuery你可以做这样的事情:



Using jQuery you can do something like this:

var labelValue =


' #dayId~label:nth-​​of-type(2)')。text();
('#dayId ~label:nth-of-type(2)').text();





请注意, nth-of-type [ ^ ]是一个CSS3选择器,所以它可能不适用于旧浏览器(但它将适用于所有现代浏览器)。代字号代表一般兄弟选择器 [ ^ ],如果我是正确的话,也是一个CSS3功能。



Mind you, nth-of-type[^] is a CSS3 selector, so it might not work on older browsers (but it will on all modern browsers). The tilde symbol represents the general sibling selector[^], also a CSS3 feature if I'm correct.


这篇关于如何使用javascript获取下一个标签名称旁边的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆