可能最容易通过代码显示:
<form>
<select class="some-jquery-class">...</select>
<input type="submit" value="submit">
</form>
<form>
<select class="some-jquery-class">...</select>
<input type="submit" value="submit">
</form>
<form>
<select class="some-jquery-class">...</select>
<input type="submit" value="submit">
</form>
然后jquery看起来像:
$(".some-jquery-class").click(function() {
// change the color of the submit button underneath and not any other
});
如何找到相对于所选元素的元素?
答案 0 :(得分:3)
你可以使用next()
来获得
$('.some-jquery-class').on('click', function() {
$(this).next('input').css({color: 'red'});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<button class="some-jquery-class">...</button>
<input type="submit" value="submit">
</div>
<div>
<button class="some-jquery-class">...</button>
<input type="submit" value="submit">
</div>
<div>
<button class="some-jquery-class">...</button>
<input type="submit" value="submit">
</div>
&#13;