How can I make a button so that it clicks on the click / falls, and on the second click it takes on the original value.
2 answers
2 pictures - btn_on.jpg , btn_off.jpg
Js:
function switchButton(name) { var bImg = document.getElementById(name+'_img'); var bInput = document.getElementById(name+'_input'); if (!bImg || !bInput) return false; bImg.src = (bInput.value) ? 'btn_off.jpg' : 'btn_on.jpg'; bInput.value = (bInput.value) ? 0 : 1; } HTML:
<input type="hidden" id="rememberme_input" name="rememberme" value="0" /> <img id="rememberme_img" onclick="switchButton('rememberme')" src="btn_off.jpg" /> ΠΠ°ΠΏΠΎΠΌΠ½ΠΈΡΡ ΠΌΠ΅Π½Ρ This is a complete set, you can put in a form ( $_POST['rememberme'] will come), replace only the paths to the pictures. Well, the styles must be prescribed, yes)
The most convenient way is to wrap the php-function.
|
$(selector).toggle(function(){ $(this).addClass("clicked"); }, function(){ $(this).removeClass("clicked"); }); //clicked - ΠΊΠ»Π°ΡΡ, ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°ΡΡΠ΅ΠΉ ΠΊΠ½ΠΎΠΏΠΊΡ Π½Π°ΠΆΠ°ΡΠΎΠΉ |