为了账号安全,请及时绑定邮箱和手机立即绑定

带一个参数的函数

带一个参数的函数

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 关注
  • 1008 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信