我試圖用內聯樣式強制對輸入按鈕進行一些更改。我使用jQuery的html函數。它的工作原理第一次,當我+按鈕點擊,但是當我在點擊不工作 - 按鈕jquery html函數第二次不能正常工作
<div id='div_bouton_moins'><input type=button value='-' id='bouton_moins' style='background-color:green !important'></div>
<div id='div_bouton_plus'><input type=button value='+' id='bouton_plus' style='background-color:red !important'></div>
$('#bouton_moins').click(function(){
$('#div_bouton_plus').html("<input type=button value='+' id='bouton_plus' style='background-color:red !important'>")
$('#div_bouton_moins').html("<input type=button value='-' id='bouton_plus' style='background-color:green !important'>");
});
$('#bouton_plus').click(function(){
$('#div_bouton_plus').html("<input type=button value='+' id='bouton_plus' style='background-color:green !important'>");
$('#div_bouton_moins').html("<input type=button value='-' id='bouton_plus' style='background-color:red !important'>");
});
https://jsfiddle.net/z148xexp/
感謝所有
您應該看到[.toggle()](http://api.jquery.com/toggle /) –
您的點擊處理程序中的每個按鈕都具有id ='bouton_plus''的ID。解決這個問題,它工作正常。但是我正在關閉這個,因爲你真正的問題是事件代表團。 https://jsfiddle.net/j08691/z148xexp/5/ – j08691