0
簡單地說:我的目標是在一個頁面上有兩個按鈕,以便在按下第一個按鈕時顯示「1」,當第二個按鈕顯示時顯示「2」被按下。這適用於無線電輸入,但是當我從Twitter Bootstrap添加按鈕標籤時,它不再起作用。我無法讓jQuery使用引導按鈕
首先,這裏是我正在使用的jQuery。我想跨度的值更改爲按下按鈕的價值:
<span id="val">0</span>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(function() {
$('input[type=radio]').click(function() {
$("#val").html($(this).val());
});
});
</script>
它正常工作與此:
<input type="radio" Id="Radio1" value="1" name="a">
<input type="radio" Id="Radio2" value="2" name="a">
但我這樣做的時候,就不再工作(我可以看到,按下按鈕,而是跨度值保持爲0):
<div class="btn-group" data-toggle="buttons">
<label type="button" for="Radio1" class="btn btn-primary active">
<input type="radio" Id="Radio1" value="1" checked>
</label>
<label type="button" for="Radio2" class="btn btn-primary">
<input type="radio" Id="Radio2" value="2">
</label>
</div>
在我看來,像標籤標籤是造成問題,但我不確定這是爲什麼。刪除標籤使其工作,但我需要按鈕標籤。
$( '輸入[類型=無線電]')點擊(函數(){...}停止工作,因爲你實際上單擊了標籤,而不是輸入。 –