簡體   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