为什么这段代码不起作用;
HTML:
<div>
<button id="jsstyle" onclick="js_style()">Click to change table size</button>
</div>
JavaScript的:
function js_style () {
document.getElementById ("table").text.style.fontSize = "14pt";
}
答案 0 :(得分:1)
text
属性,只需像style.fontSize
那样:
<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>
&#13;
答案 1 :(得分:0)
你可以这样做:
document.getElementById("table").style.fontSize = "14pt";
以下是文档:https://www.w3schools.com/jsref/prop_style_fontsize.asp
答案 2 :(得分:0)
你会找到文件here 试试这个:
<!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>
答案 3 :(得分:0)
使用jsstyle
ID代替table
并在text
工作后删除id
function js_style() {
document.getElementById("jsstyle").style.fontSize = "48pt";
}
&#13;
<head>
<meta charset=utf-8 />
</head>
<div> <button id="jsstyle" onclick="js_style()">Click to change table size</button> </div>
&#13;