2015-11-25 85 views
-1

我發現教程像 this但是當我添加的輸入,第二輸入不想讓點擊按鈕,使輸入在其旁邊的jQuery

這裏是代碼:

<html> 
 
<head> 
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script type="text/javascript"> 
 
$(document).ready(function(){ 
 
$("button").click(function() { 
 
$(this).next().removeAttr("disabled") 
 
.focus() 
 
}); 
 
}); 
 
</script> 
 
</head> 
 
<body> 
 
<button>Enable</button> 
 
<input type="text" disabled="disabled" value="data" /> 
 
<input type=text disabled="disabled" value='data2'/> 
 
</body> 
 
</html>

+0

如果您想啓用第二個輸入呢? – Tushar

回答

2

這是因爲.next()的目標是緊接着的下一個兄弟姐妹。如果要同時定位兩者,請使用.nextAll()以及禁用作爲屬性選擇器。還要注意,你不能將兩個元素集中在一起。對於您可以使用.first()瞄準第一個元素組匹配隨着.focus()關注它:

$("button").click(function() { 
$(this).nextAll('[disabled]').removeAttr("disabled").first().focus() 
}); 

Working Demo

+0

但爲什麼在標籤形式它不起作用? –

+0

因爲禁用不是標籤,輸入是。 –

+0

那我該怎麼辦?我爲了編輯表格 –