我有这个html片段:
<label>
<input type="checkbox"/>
text here
</label>
Run Code Online (Sandbox Code Playgroud)
在我的js中,我想检索'text here'值
这是我的js:
$('input[type=checkbox]').click(function (e) {
var msg = e.target.closest???
});
Run Code Online (Sandbox Code Playgroud)
您可以使用DOM节点nextSibling属性:
$('input[type=checkbox]').click(function (e) {
var msg = this.nextSibling.nodeValue;
console.log(msg);
});
Run Code Online (Sandbox Code Playgroud)
$('input[type=checkbox]').click(function (e) {
var msg = this.nextSibling.nodeValue;
alert(msg);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label>
<input type="checkbox" />text here
</label>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
723 次 |
| 最近记录: |