選項之一:
呼叫myFunction的的onclick並傳遞ID和字體大小,它們處理腳本文件中的操作。 (好)
HTML:
<div class="Appraisals" id="change">
<div align="left"><span class="Block1">Random text that nobody cares about.
Random text that nobody cares about.Random text that nobody cares about.</span>
</div>
<button type="button" onclick="myFunction('change', '50px');" > Click Me!</button>
Click Me!
</button>
</div>
<div class="inspire"> <img src="inspire.jpg" alt="Crest" height="200"></div>
JS:
<script>
function myFunction(element, clr) {
var changeId = document.getElementById(element);
changeId.style.fontSize=clr;
}
</script>
選項二:
手柄與HTML中的操作。 (不好)
<div class="Appraisals" id="change">
<div align="left"><span class="Block1">Random text that nobody cares about.
Random text that nobody cares about.Random text that nobody cares about.</span>
</div>
<button type="button" onclick="document.getElementById("change").style.fontSize="50px"" > Click Me!</button>
Click Me!
</button>
</div>
<div class="inspire"> <img src="inspire.jpg" alt="Crest" height="200"></div>
方案三:
使用jQuery。 (非常好)
首先調用jQuery的CDN:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
他們:
<script>
$(document).ready(function() {
$('button').click(function() {
$('#change').css('font-size', '50px');
});
});
</script>
乾杯的答覆,我試過,並像以前一樣,沒有。 – user3071724
你用正確的語法試過了嗎? – jmore009
是的。即使使用你推薦的小提琴什麼也沒做,還有什麼提示? – user3071724