简体   繁体   English

Javascript无法在浏览器中运行? (Firefox,Chrome和Safari)

[英]Javascript not working in browser? (Firefox, Chrome and Safari)

http://pastebin.com/K2miHiAj http://pastebin.com/K2miHiAj

That's where the code is located ^ 这就是代码所在的位置^

I use both Coda 2 and BBEdit to run the code on and test it, and it works perfectly fine on them! 我使用Coda 2和BBEdit来运行代码并对其进行测试,它在它们上运行得非常好! However, whenever I try a browser, the code never runs properly. 但是,每当我尝试使用浏览器时,代码都无法正常运行。 For this assignment the code has to work on Firefox. 对于此分配,代码必须适用于Firefox。

http://oi47.tinypic.com/2lk9yx4.jpg http://oi47.tinypic.com/2lk9yx4.jpg

You've defined the function myFunction AFTER trying to attach it to the onclick , therefore the thing in onclick="myFunction()" is undefined . 你试图将它附加到onclick后定义了函数myFunction ,因此onclick="myFunction()"未定义的
Solution: seperate your JavaScript from your HTML. 解决方案:从HTML中分离JavaScript。

// attach listener to window.load
window.addEventListener('load',function () {
    // attach listener to your button
    document.getElementById('clickme')
        .addEventListener('click',
                          myFunction,
                          false);
}, false);

Look at this fiddle . 看看这个小提琴


Edit: complete final code here . 编辑: 在此完成最终代码。

暂无
暂无

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

相关问题 Javascript在Safari中运行,但不适用于Chrome或Firefox - Javascript working in Safari but not Chrome or Firefox For循环中的Javas If语句可在Chrome和Safari中运行,但不能在Firefox中运行 - Javascript If statement in a For loop working in Chrome and Safari but not Firefox Javascript未在Firefox上执行,适用于Chrome和Safari - Javascript not executed on Firefox, working on Chrome & Safari javascript的onClick在chrome,firefox等浏览器中不起作用 - onClick of javascript not working in Browser like chrome,firefox Javascript仅在Chrome浏览器中有效,而在Firefox中不可用 - Javascript only working in Chrome browser not in Firefox 可以在Chrome中正常工作的JavaScript jQuery代码,而不能在Firefox,Safari,IE中运行 - Simply javascript jQuery code working in Chrome, not Firefox, Safari, IE Javascript / jQuery无法在Firefox,Safari和IE中运行。 精通Opera和Chrome - Javascript/jQuery not working in Firefox, Safari and IE. Fine in Opera and Chrome Javascript / JQuery突然在Chrome和Firefox中停止工作,但仍在Safari中工作 - Javascript/JQuery suddenly stops working in Chrome and Firefox, but still works in Safari Javascript(JS)应用程序可在Chrome上运行,但不能在mozilla firefox / safari上运行 - Javascript (JS) application working on Chrome but not on mozilla firefox/safari JavaScript代码仅在Chrome中有效,而在Firefox,IE,Opera和Safari中无效 - JavaScript code working only in Chrome but not in Firefox, IE, Opera and Safari
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM