简体   繁体   中英

JavaScript working on fiddle but not in site

Good day!

I have recently acquired a code and was passed on using fiddle. It works fine on the fiddle but when I am trying to implement it on my site.

Head tag contains:

<head>
<title>NQA Insert</title>
<script type="text/javascript" src="NQAa.js">
</script>
</head>

While NQA.js contains:

$('#bill50').on('change', function() {
var date30 = new Date($(this).val());
date30.setDate(date30.getDate()+30);
var date20 = new Date($(this).val());
date20.setDate(date20.getDate()+60);
$('#bill30').val(date30.toJSON().slice(0,10));
$('#bill20').val(date20.toJSON().slice(0,10));
});

Note 1: If you input a date on bill50, the value on bill30 and bill20 also changes. Note 2: I am implementing this on a php page. Maybe this helps...

Why is it that when implementing it on the site, it doesn't work at all? Is there anything wrong in my calling of the jscript..?

you need to include the jQuery library, as you can see in your jsFiddle he's including jQuery 1.8.3, you should add it in your "head" tag just before the js script you bought.

You'll get something like this:

<head>
<title>NQA Insert</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js">
<script type="text/javascript" src="NQAa.js">
</script>
</head>

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