我有一個實例,其中我的datepickers不會按按鈕工作,所以我找到最接近的輸入和.click()或.focus()(因爲它是datepicker,因爲相同的字段會受到影響)。爲了演示,從按鈕/圖標點擊 - 找到最接近的輸入並聚焦/點擊它。如果正確,邊框將呈藍色。 http://jsfiddle.net/81tvr0op/更改最接近的輸入值?
HTML
<table>
<tr>
<th>
<div class="input-group date">
<input type="text" />
<span class="input-group-btn">
<button class="btn default" type="button">
<i class="fa fa-calendar"></i>
Icon
</button>
</span>
</div>
</th>
</tr>
</table>
jQuery的
...像
$(".date > span > button").on('click', function (e) {
e.preventDefault();
$(this).closest("th").find("input:text").click();
});
...對不對?