2017-10-31 9 views
-2

이 코드가 작동하지 않는 이유는 무엇입니까?자바 스크립트에서 글꼴 크기를 변경하는 방법

HTML :

<div> 
     <button id="jsstyle" onclick="js_style()">Click to change table size</button> 
    </div> 

자바 스크립트 : 여기

document.getElementById("table").style.fontSize = "14pt"; 

다큐먼트는 다음과 같습니다 :

function js_style() { 
    document.getElementById ("table").text.style.fontSize = "14pt"; 
}  
+1

제거 '텍스트'. 이렇게 :'document.getElementById ("table"). style.fontSize = "14pt";' – Chris

+1

'테이블'이란 무엇입니까? – epascarello

답변

1

테이블은 어디에 있습니까? 더 text 속성은 없다, 단지 같은 style.fontSize을 수행

<!DOCTYPE html> 
 
<html> 
 
<body> 
 

 
<p id="myP">This is a paragraph.</p> 
 

 
<button type="button" onclick="myFunction()">Set font size</button> 
 
    
 
<script> 
 
function myFunction() { 
 
    document.getElementById("myP").style.fontSize = "50pt"; 
 
} 
 
</script> 
 

 
</body> 
 
</html>

0

당신이 문서 here 이 시도 찾을 수 있습니다대신 table의 ID와 idtext 제거의 작업

function js_style() { 
 

 
    document.getElementById("jsstyle").style.fontSize = "48pt"; 
 

 
}
<head> 
 
    <meta charset=utf-8 /> 
 
</head> 
 

 
<div> <button id="jsstyle" onclick="js_style()">Click to change table size</button> </div>

+1

무엇을 시도해보십시오. – Durga

+0

@Durga 설명서 링크 추가 :) –

0

사용:

<div><button id="jsstyle" onclick="js_style()">Click to change table size</button></div> 
 

 
<table id="table"> 
 
<tr> 
 
<td>asdasdas</td> 
 
</tr> 
 
</table> 
 

 
<script> 
 
    function js_style() { 
 

 
    document.getElementById("table").style.fontSize = "14pt"; 
 
    } 
 
</script>