卓詠瀅python期中考javascript按鈕button事件onchange
卓詠瀅輸入參數
輸入k value="1" id="k"> 輸入k value="1" id="m"> 輸入k value="1" id="n">JS程式碼
const space=' ', slash='/', backslash='\\', cr='\n';function row1(k,m){ for(let i=0; i<k;i++){ for(let ii=0; ii<m; ii++){ for(let j=0; j<k-i-1; j++) out+=space; out+=slash; for(let j=0; j<2*i; j++) out+=space; out+=backslash; for(let j=0; j<k-i-1;j++) out+=space;}; out+=cr;};};function row2(k,m){ for(let i=0; i<k; i++){ for(let ii=0; ii<m; ii++){ for(let j=0; j<i; j++) out+=space; out+=backslash; for(let j=0; j<2*k-2*i-2; j++) out+=space; out+=slash; for(let j=0; j<i;j++) out+=space;}; out+=cr;};};function abc(){ k = document.getElementById('k').value; m = document.getElementById('m').value; n = document.getElementById('n').value; out ='<pre>劉任昌\n'; for(let i=0; i<n; i++){ row1(k,m); row2(k,m);} out += '</pre>'; document.getElementById('out').innerHTML=out;} function change(x){ //python的自訂函數def,javascript function document.body.style.backgroundColor = x.options[x.selectedIndex].text; }
const space=' ', slash='/', backslash='\\', cr='\n';
function row1(k,m){
for(let i=0; i<k;i++){
for(let ii=0; ii<m; ii++){
for(let j=0; j<k-i-1; j++)
out+=space;
out+=slash;
for(let j=0; j<2*i; j++)
out+=space;
out+=backslash;
for(let j=0; j<k-i-1;j++)
out+=space;};
out+=cr;};};
function row2(k,m){
for(let i=0; i<k; i++){
for(let ii=0; ii<m; ii++){
for(let j=0; j<i; j++)
out+=space;
out+=backslash;
for(let j=0; j<2*k-2*i-2; j++)
out+=space;
out+=slash;
for(let j=0; j<i;j++)
out+=space;};
out+=cr;};};
function abc(){
k = document.getElementById('k').value;
m = document.getElementById('m').value;
n = document.getElementById('n').value;
out ='<pre>劉任昌\n';
for(let i=0; i<n; i++){
row1(k,m);
row2(k,m);}
out += '</pre>';
document.getElementById('out').innerHTML=out;}
function change(x){
//python的自訂函數def,javascript function
document.body.style.backgroundColor = x.options[x.selectedIndex].text;
}
HTML
<!--HTML註解-->
<LINK REL='STYLESHEET' HREF='index.css'>
<SCRIPT SRC='index.js'></SCRIPT>
<h1>卓詠瀅輸入參數</h1>
輸入k<input type="number" value="1" id="k"></input><br>
輸入m<input type="number" value="1" id="m"></input><br>
輸入n<input type="number" value="1" id="n"></input><br>
<button onclick="abc()">執行自訂函數</button>
<h1>重點</h1>
span手掌張開拇指到小指,短橋梁長度
VScode是IDE整合開發環境。
CTRL+SHIFT+L一次改全部
Intergrated Development Enviroment
alert內建函數,自訂函數abc
<h1>卓詠瀅輸出結果</h1>
<div class="monkey " id="out"></div>
CSS
h1{background-color: purple; color: white; border: 10px solid red; text-align:center; padding: 5px}
ul{background-color: green; color: white; font-size: 2em;line-height:1.5}
input{font-size:24px;background-color:rgb(210, 250, 215);}
.monkey{font-size:36px;}
.spanstyle{font-size: 24px;font-weight: bold;}
pre{color: azure;background-color: beige;}

留言
張貼留言