<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function searchByName(){
//태그에 설정된 name속성값을 dom조회
var name = window.prompt("name속성을 입력하세요");
var txt = window.prompt("넣을 값을 입력하세요");
var list = document.getElementsByName(name);
for(i=0;i<list.length;i++){
list[i].value=txt;
}
}
function searchByTagName(){
//태크 명으로 dom 조회
var tagName = window.prompt("태그명을 입력하세요","");//""는 디폴트(default)
var txt = window.prompt("넣을 값을 입력하세요","");
var list = document.getElementsByTagName(tagName);//ex : ("tr");
for(i=0;i<list.length;i++){
list[i].value=txt;
}
}
function searchById(){
var txt = prompt("이름을 입력하세요","")
var myName = document.getElementById("myName");//가장 많이 쓰임
myName.value=txt;
}
</script>
</head>
<body>
<input type="text" name="name" id="myName">
<input type="text" name="name">
<input type="text" name="name">
<input type="text" name="name">
<input type="text" name="name"><br>
<input type="text" name="age">
<input type="text" name="age">
<input type="text" name="age">
<input type="text" name="age">
<input type="text" name="age"><br>
<textarea name="ta"></textarea>
<textarea name="ta"></textarea><br>
<button onclick="searchByName()">name으로조회</button>
<input type="button" value="tag명으로조회" onclick="searchByTagName()">
<button onclick="searchById()">id로 조회</button>
</body>
</html>