如何在不使用ID的情况下获取值为WAN
的li的父级?我已尝试在$(this).parent().parent();
onclick
中使用input
,但仅返回点击的li
。
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Application Integration">Application Integration
<ul class="">
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Windows">Windows
<ul class="">
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Leitungen">Leitungen
<ul class="">
<li><span> </span><input type="checkbox" name="WAN">WAN</li>
<li><span> </span><input type="checkbox" name="Mail">Mail</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
我如何访问整个构造(从<input type="checkbox" name="Application Integration">Application Integration
开始)?
已经非常感谢您的任何建议。
答案 0 :(得分:2)
你之后是这样的吗?
.xxx {
border: solid 3px orange;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Application Integration">Application Integration
<ul class="">
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Windows">Windows
<ul class="">
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Leitungen">Leitungen
<ul class="">
<li><span> </span><input type="checkbox" name="WAN">WAN</li>
<li><span> </span><input type="checkbox" name="Mail">Mail</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
$('[type="checkbox"]').on('click', function(){
$(this).parents('li').last().children('input').not($(this)).prop('checked', true);
});
或反过来
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Application Integration">Application Integration
<ul class="">
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Windows">Windows
<ul class="">
<li>
<span class="expanded">-</span>
<input type="checkbox" name="Leitungen">Leitungen
<ul class="">
<li><span> </span><input type="checkbox" name="WAN">WAN</li>
<li><span> </span><input type="checkbox" name="Mail">Mail</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
var crypto = require('crypto')
function encryptstring(str) {
var cipher = crypto.createCipheriv('aes-256-cbc', 'NFd6N3v1nbL47FK0xpZjxZ7NY4fYpNYd', 'TestingIV1234567'),
encrypted = cipher.update(str, 'utf-8', 'base64');
encrypted += cipher.final('base64');
return encrypted;
}
console.log(encryptstring("Testing 111111111111111111111111111111111111111111"))
答案 1 :(得分:1)
使用$(this).parent().closest('li');
如果您专门针对输入,可以使用:
$("input[name='WAN']").click(function(){
$("input[name]='Application Integration'").addClass("wan-clicked");
});
答案 2 :(得分:0)
我认为你需要jquery的.closest
方法。它可以让你通过DOM直到遇到某个选择器。
$('input[name="WAN"]').click(function(event) {
var closestli = $(event.target).closest('li');
var closestul = $(event.target).closest('ul');
var closestConstruct = $(event.target).closest('input[name="Application Integration"]');
});
与任何jquery选择一样,如果没有&#34;祖先&#34;你可以获得一个空对象。匹配您的选择器。