简体   繁体   中英

javascript not working from notepad++

I am having trouple with my javaScript not running in Waterfox for a standard .html file i made using notepad++

Below is my JavaScript

document.getElementByID("foot01").innerHTML = "<p>;  " + new Data().getFullYear() + " Extra Technical, Out of this world.</p>";

and below is the section of HTML in my file that calls this Jscript

<footer id="foot01"></footer>
</div>
<script type="javascript" src="script.js"></script>

What is the issue here and how can i fix it, i made sure that all is spelt correctly and still cant figure it out.

<script type="javascript" src="script.js"></script> ^^^^^^^^^^

That is not a MIME type. It should be application/javascript (or text/javascript for compatibility with older browsers). But the type attribute is optional, so just remove it entirely as the only purpose it serves (when you are writing JS) is to allow you make typos that break the script.

A validator should have picked that up.

 getElementByID

That is not how you spell Id , which needs a lower-case d . JavaScript is case sensitive.

 Data().getFullYear()

That is not how you spell Date , which ends in an e not an a .

use : new Date().getFullYear()

not new data()

You made two of those mistakes. Correct those two and it will work smooth.

document.getElementById("foot01").innerHTML = "<p>" + new Date().getFullYear() + " Extra Technical, Out of this world.</p>";

Fiddle - http://jsfiddle.net/ylokesh/5j1w12vk/

To identify these issues, you should open developer tools in browser window. You will get clear definition of errors in console. That will save your time to resolve small mistakes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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