Javascript W3C教程示例不在Mac上使用尾波

Javascript W3C教程示例不在Mac上使用尾波,javascript,html,Javascript,Html,我正在W3Schools网站上学习JavaScript教程,我有以下代码: <html> <head> <title>Hello!</title> </head> <body> <script type="text/javascript"> function confirmShow { var r = confirm("Press one...") if (r == true)

我正在W3Schools网站上学习JavaScript教程,我有以下代码:

<html>

<head>

<title>Hello!</title>

</head>

<body>

<script type="text/javascript">
function confirmShow
{
    var r = confirm("Press one...")
    if (r == true)
    {
        alert("Button pressed == OK")
    }

    if (r == false)
    {
        alert("Button pressed == Cancel")
    }
}
</script>
<input type="button" onclick="confirmShow()" value="Show Confirm Box" />
</body>



</html>

你好
函数确认显示
{
var r=确认(“按一…”)
如果(r==true)
{
警报(“按下按钮=正常”)
}
如果(r==false)
{
警报(“按下按钮=取消”)
}
}
无论何时我在Coda或Safari中预览它,警报都不会出现


提前谢谢

我不知道这是否是您的问题,但您的按钮在
标签之外。那可能会给你带来麻烦


另外,人们通常会在
元素中放置这样的脚本。仅供参考。

我不知道这是否是您的问题,但您的按钮在
标签之外。那可能会给你带来麻烦

另外,人们通常会在
元素中放置这样的脚本。仅供参考。

“函数确认显示”=>“函数确认显示()

Firebug很适合js调试,试试吧。Safari也有选项,当然。

“函数confirmShow”=>“函数confirmShow()”

Firebug很适合js调试,试试吧。Safari也有很多选择,好吧。

1)这里充满了错误和遗漏。更好的教程可以在howtocreate.co.uk上找到

2) 您没有DOCTYPE声明,并且使用的是XHTML语法

2.1)IE不支持true,有关更多信息,请参阅webdeviout.net/articles/careed-of-xhtml 3) 您需要根据规范在一个元素以及另一个块级元素中封装

请参阅下面的HTML5文档。注意位置和语法

<!DOCTYPE html>
<html>
<head>
    <title>Hello!</title>
<script>
function confirmBox() {
    var ret = confirm('Some Text');
/*
Note the 3 equal signs. This is a strict comparison operator, to check both the 'value' as well as the type. see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators for more
*/
    if(ret === true) { 
        alert('Alert box for "Okay" value');
    }
    else if(ret === false) {
        alert('Alert box for "Cancel" value');
    }
}
window.onload = function() {
    // Execute the confirmBox function once the 'button' is pressed.
    document.getElementById('confirmBox').onclick = confirmBox;
}
</script>
</head>
<body>


<form>
<p>
<input type="button" id='confirmBox' value="Show Confirm Box">
</p>
</form>


</body>
</html>

你好
函数confirbox(){
var ret=确认(“某些文本”);
/*
请注意3个等号。这是一个严格的比较运算符,用于检查“值”和类型。请参阅https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators 更多
*/
如果(ret==true){
警报(‘正常’值的警报框);
}
否则,如果(ret==false){
警报(“用于“取消”值的警报框”);
}
}
window.onload=函数(){
//按下“按钮”后,执行confirmBox功能。
document.getElementById('confirbox')。onclick=confirbox;
}

1)学校充满了错误和遗漏。更好的教程可以在howtocreate.co.uk上找到

2) 您没有DOCTYPE声明,并且使用的是XHTML语法

2.1)IE不支持true,有关更多信息,请参阅webdeviout.net/articles/careed-of-xhtml 3) 您需要根据规范在一个元素以及另一个块级元素中封装

请参阅下面的HTML5文档。注意位置和语法

<!DOCTYPE html>
<html>
<head>
    <title>Hello!</title>
<script>
function confirmBox() {
    var ret = confirm('Some Text');
/*
Note the 3 equal signs. This is a strict comparison operator, to check both the 'value' as well as the type. see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators for more
*/
    if(ret === true) { 
        alert('Alert box for "Okay" value');
    }
    else if(ret === false) {
        alert('Alert box for "Cancel" value');
    }
}
window.onload = function() {
    // Execute the confirmBox function once the 'button' is pressed.
    document.getElementById('confirmBox').onclick = confirmBox;
}
</script>
</head>
<body>


<form>
<p>
<input type="button" id='confirmBox' value="Show Confirm Box">
</p>
</form>


</body>
</html>

你好
函数confirbox(){
var ret=确认(“某些文本”);
/*
请注意3个等号。这是一个严格的比较运算符,用于检查“值”和类型。请参阅https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators 更多
*/
如果(ret==true){
警报(‘正常’值的警报框);
}
否则,如果(ret==false){
警报(“用于“取消”值的警报框”);
}
}
window.onload=函数(){
//按下“按钮”后,执行confirmBox功能。
document.getElementById('confirbox')。onclick=confirbox;
}

功能确认显示 {

函数confirmShow() { ?功能确认显示 {

函数confirmShow() {

哦,刚刚注意到。我把按钮放回了主体标签,它仍然不起作用。哦,刚刚注意到。我把按钮放回主体标签,它仍然不起作用。离题:W3Schools经常过时或实践不佳。要获得更好的替代方案,请尝试离题中的建议:W3Schools经常过时或公关不佳为了更好的选择,请尝试Ok中的推荐,我不认为我使用的是XHTML语法,因为教程是关于HTML的,而不是XHTML.Hmm…好的,我不认为我使用的是XHTML语法,因为教程是关于HTML的,而不是XHTML.Hmm。。。