繁体   English   中英

W3Schools教程示例在Mac上无法与Coda一起使用

[英]W3Schools tutorial example not working with Coda on Mac

我正在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>

并且无论何时在Coda或Safari中预览它,警报都不会显示。

提前致谢!

“功能确认秀” =>“功能确认秀()”

Firebug非常适合js调试,请尝试一下。 Safari也有其他选项,即AFAIK。

功能ConfirmShow {

函数validateShow(){?

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

通常,通常会将这样的脚本放在<head>元素中。 仅供参考。

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

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

2.1)IE不支持true,有关更多信息,请参见webdevout.net/articles/beware-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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM