예제1
<script>
function hz(a) {
window.alert(a.value);
}
</script>
<input type='button' value='홈짱닷컴 Homzzang.com' name='' class='' onclick='hz(this)'>
결과 보기
예제2
<script>
function hz(a) {
document.getElementById('homzzang').innerHTML = a.value;
}
</script>
<input type='button' value='홈짱닷컴 Homzzang.com' name='' class='' onclick='hz(this)'>
<div id='homzzang'><div>
결과 보기
예제3
<style>
.red {color:red;}
.blue {color:blue;}
</style>
<script>
function chk() {
var a = document.getElementById('hz').value;
if(a == '') {
document.getElementById('notice').innerHTML= '입력 X';
document.getElementById('notice').setAttribute('class','red');
} else {
document.getElementById('notice').innerHTML= '입력 O';
document.getElementById('notice').setAttribute('class','blue');
}
}
</script>
<input type='text' name='hz' value='' placeholder='' id='hz'>
<input type='button' value='확인' name='' class='' onclick='chk()'>
<div id='notice'></div>
결과 보기
※ 대소문자 구별 주의
최신댓글