由于某种原因,我的JavaScript函数无法工作
My JavaScript function is not working for some reason
由于某些原因,此函数不起作用,警报框也不会弹出,但我的代码与另一个起作用的页面完全相同。我是不是错过了什么愚蠢的东西?
<!DOCTYPE html>
<html>
<head>
<title>What's my name?</title>
<script>
function whatsMyName() {
var first = "firstname";
var last = "lastname";
alert("My name is"+" "first+" "+last);
}
</script>
</head>
<body>
<button type="button" onclick=whatsMyName()>What's my name?</button>
<br><br>
<a href="index.html">Return</a>
</body>
</html>
您似乎把引号搞得一团糟。
为您修复了这个问题:
<!DOCTYPE html>
<html>
<head>
<title>What's my name?</title>
<script>
function whatsMyName() {
var first = "Corey";
var last = "LeBlanc";
alert("My name is " + first + " " + last);
}
</script>
</head>
<body>
<button type="button" onclick="whatsMyName();">What's my name?</button>
<br><br>
<a href="index.html">Return</a>
</body>
</html>
更改:
-
alert("My name is"+" "+first+" "+last); // missing "+" before "first"
-
<button type="button" onclick="whatsMyName()">What's my name?</button>
onclick="whatsMyName()"
应该是。。
<button type="button" onclick="whatsMyName()">What's my name?</button>
也称为CCD_ 3;
您需要在".."中编写函数,并更改alert。。如下
alert("My name is" + " " +first+ " " +last);
<body>
<button type="button" onclick = "whatsMyName()">What's my name?</button>
<br><br>
<a href="index.html">Return</a>
</body>
两个错误:
更改:<button type="button" onclick=whatsMyName()>What's my name?</button>
收件人:<button type="button" onclick="whatsMyName()">What's my name?</button>
更改:alert("My name is"+" "first+" "+last);
收件人:alert("My name is"+" "+first+" "+last);
相关文章:
- 咖啡的Javascript订单总数无法使函数正常工作.请协助
- removeClass函数没有'工作不正常
- 你能解释一下这个阶乘函数是如何工作的吗?
- JavaScript链接在点击时不起作用;函数在页面加载时工作
- jQuery加载的async和ready函数不工作
- 更改智能表中的页面将停止JQuery函数的工作
- 为什么不是'我的函数在解析云代码中工作吗?当我在Angular和Express中测试时,它是有效的
- jQuery函数不能只在一个页面上工作
- 如何检查这个代码点火器php函数是否工作,该函数是否在ajax url中使用
- 从js引擎的角度来看闭包和构造函数是如何工作的
- appendChild在函数外部工作,但在函数内部不工作
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- 由于某种原因,我的JavaScript函数无法工作
- 为什么递归生成器函数没有't在ES2015工作
- 我需要一个jQuery函数来只工作在700px以上的屏幕大小,无法在我的代码中发现错误
- 从控制台中的工作函数转换为工作脚本.(请参阅编辑)
- Angular JS-工作函数中的“错误:[$interpole:interr]Can't interpole:
- 简化工作函数以替换特定单词
- 为什么不在回调中工作函数?
- InnerHTML不工作:函数未定义