◽ HTML & CSS & JS, jQuery

[javascript - (30) ] input type 동적으로 변경하기

<input type="button" name="test" value=100 />
<script>
    var test = document.getElementsByName("test")[0]; test.setAttribute('type', 'hidden');
</script>

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
코드정리
 
<!DOCTYPE html> 
<html> 
<body> 
 
<input value="OK"> 
 
<p>Click the button below to change the input field to an input button.</p> 
 
<button onclick="myFunction()">Try it</button> 
 
<p>Internet Explorer 8 and earlier does not support the setAttribute method.</p> 
 
<script> 
function myFunction() { 
  document.getElementsByTagName("INPUT")[0].setAttribute("type""button");  
</script> 
 
</body> 
</html> 
 

실행 보기
https://www.w3schools.com/code/tryit.asp?filename=GF6OYWHQVMS5

푸터바