亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

帶一個參數的函數

帶一個參數的函數

qq_慕標6304929 2020-03-28 15:57:37
請在預置代碼中編寫Javascript代碼,使預覽頁面實現如下效果:點擊Morning按鈕,引用id為demo的段落內容顯示Good?Morning!; 點擊Evening按鈕,引用id為demo的段落內容顯示Good?Evening!;任務與要求請定義函數myFunction,傳入一個參數text,使id為demo的段落返回text的值請在form標簽內創建一個按鈕,值為Morning,調用函數myFunction,點擊按鈕,段落內容顯示Good Morning!請在form標簽內創建一個按鈕,值為Evening,調用函數myFunction,點擊按鈕,段落內容顯示Good Evening!<!DOCTYPE html><html>?<head>?</head>?<body><form>?</form>?<p id="demo"></p></body>?</html>
查看完整描述

2 回答

已采納
?
蓮_蓶濏__

TA貢獻25條經驗 獲得超3個贊

<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8"?/>
<title></title>
</head>
<body>
<form>
<button?onclick="myFunction('Morning')"??type="button">Morning</button>
<button?onclick="myFunction('Evening')"??type="button">Evening</button>
</form>
<p?id="demo"></p>
<script>
function?myFunction(text)?{
document.getElementById('demo').innerHTML?=?'Good?'?+?text?+?'!';
}
</script>
</body>
</html>


查看完整回答
1 反對 回復 2020-03-30
?
蓮_蓶濏__

TA貢獻25條經驗 獲得超3個贊

<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8"?/>
<title></title>
</head>
<body>
<form></form>
<div?id="demo"></div>
<script>
function?myFunction(text)?{
document.getElementById('demo').textContent?=?'Good?'?+?text?+?'!;';
}
var?oBtnMor?=?document.createElement('input');
oBtnMor.type?=?"button";
oBtnMor.onclick?=?function()?{
myFunction('Morning');
};
oBtnMor.value?=?'Morning';
document.forms[0].appendChild(oBtnMor);
var?oBtnEve?=?document.createElement('input');
oBtnEve.type?=?"button";
oBtnEve.onclick?=?function()?{
myFunction('Evening');
};
oBtnEve.value?=?'Evening';
document.forms[0].appendChild(oBtnEve);
</script>
</body>
</html>


查看完整回答
反對 回復 2020-03-28
  • qq_慕標6304929
    qq_慕標6304929
    按鈕有點復雜,<button onclick="myFunction()"></button>這個不可以嗎
  • qq_慕標6304929
    qq_慕標6304929
    這段代碼請你幫忙看看,有點問題 <!DOCTYPE html> <html> <head> </head> <body> <form> <button onclick="myFunction()">Morning</button> <button onclick="myFunction()">Evening</button> </form> <p id="demo"></p> <script> function myFunction(text) { document.getElementById('demo').innerHTML = 'Good ' + text + '!'; } </script> </body> </html>
  • 蓮_蓶濏__
    蓮_蓶濏__
    可以啊 只是他說創建我以為是以DOM方式創建
  • 2 回答
  • 0 關注
  • 1125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號