0
我需要幫助在表中爲標記添加屬性。使用jQuery在td標記中添加一個屬性值
我有一個輸出圖像複選框的循環。 (見下圖)。當用戶點擊第一個時,它啓用應該啓用下一個複選框。
我想用戶點擊第一個圖像,比第二個比第三個等。我不希望用戶隨意點擊任何圖像。
它的作品,如果我擺脫<td>
標籤。所以我的問題是<td>
標籤
HTML
<table class="table table-bordered">
<?php
$count = 1;
for($x=0; $x < 5; $x++){
?>
<td>
<div class="thumb">
<label for="image <?php echo $count;?>"><img class="img" src="http://s5.tinypic.com/30v0ncn_th.jpg"/></label>
<input type="checkbox" class="chk " id="image <?php echo $count;?>" name="tick" value="0" />
</div>
</td>
<?php
$count++; }
?>
</table>
的JavaScript
<script>
$(function() {
var imageSelector = 'input[type="checkbox"][name="tick"]';
$(imageSelector)
.on('click', function() {
var $this = $(this);
if($this.is(':checked')) {
$this
.nextAll(imageSelector)
.first()
.removeAttr('disabled')
.removeAttr('checked');
return;
}
$this
.nextAll(imageSelector)
.attr('disabled', 'disabled')
.removeAttr('checked');
})
.attr('disabled', 'disabled')
.removeAttr('checked')
.first().removeAttr('disabled');
});
</script>
我如何添加attribue到<td>
標籤
請點擊'<>'按鈕和粘貼HTML和JavaScript只在[MCVE] – mplungjan
_「我如何可以添加屬性標籤「_ - 'td'元素沒有'disabled'屬性。即使你設定了它,它也不會實現任何事情。 – CBroe
太好了。如果我刪除標籤它一切正常。這就是我爲什麼那樣想的原因。如何更改我的選擇器,以便用戶只能點擊第一個圖像,而不是第二個,比第三個等等 –