Created
March 12, 2017 10:20
-
-
Save Dosant/72d8eb4e44d823aa52822072cf27c462 to your computer and use it in GitHub Desktop.
Input и checkbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input id="my-input" type="text" value="Text"> | |
<button id="clear-button">Clear</button> | |
<p id="my-p">Text</p> | |
<input id="my-checkbox" type="checkbox"> | |
<p id="checkbox-text"></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input = document.getElementById('my-input'); | |
var clearButton = document.getElementById('clear-button'); | |
var p = document.getElementById('my-p'); | |
function handleUserInput() { | |
p.textContent = input.value; | |
} | |
function handleClearClick() { | |
p.textContent = ''; | |
input.value = ''; | |
} | |
input.addEventListener('input', handleUserInput); | |
clearButton.addEventListener('click', handleClearClick); | |
var checkbox = document.getElementById('my-checkbox'); | |
var checkboxText = document.getElementById('checkbox-text'); | |
handleCheckboxChange(); | |
function handleCheckboxChange() { | |
if (checkbox.checked) { | |
checkboxText.textContent = 'Чекбокс отмечен'; | |
} else { | |
checkboxText.textContent = 'Чекбокс пустой'; | |
} | |
} | |
checkbox.addEventListener('change', handleCheckboxChange); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment