Ich versuche, einige Änderungen an einem Eingabeknopf mit Inline-Stil zu erzwingen. Ich benutze die HTML-Funktion von jQuery. Es funktioniert das erste Mal, wenn ich auf die Schaltfläche + klicken, aber nicht funktioniert, wenn ich klicken Sie auf die - TasteJquery HTML-Funktion funktioniert nicht das zweite Mal
<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/
dankt allen
Sie sehen sollten [.toggle()] (http://api.jquery.com/toggle /) –
Jede Schaltfläche in Ihren Klickhandlern hat die ID 'id =' bouton_plus''. Fix das und es funktioniert gut. Aber ich schließe das, da dein wirkliches Problem die Delegierung von Ereignissen ist. https://jsfiddle.net/j08691/z148xexp/5/ – j08691