简体   繁体   中英

JQuery not working in JSP page but javascript works fine

I am facing issue while running a JSP page using tomcat server. I've included the <script> tag inside my JSP to add JQuery and my customscript JS file but unfortunately after the JSP page gets loaded JQuery doesn't work.

This is how I've included my JS file with JQuery code inside the JSP page:

<script src="js/customscript.js" type="text/javascript"></script>

For Testing purpose whether this file gets included in JSP page I tried with putting just an alert and it works fine also I tried to put simple JQuery function as:

$(document).ready(function(){
alert("JQuery called");
});   

This too works fine but when I put an onclick event outside it doesn't work? Why? Is there anything I am doing incorrect? Any suggestions?

Thanks!

Try adding a event.preventDefault() to your click function.

HTML

a href="#" id="myID class="myClass" onclick="functionClick(myEvent)"

JavaScript

function myClick(myevent){
    myevent.preventDefault();
    // Your code
    );
    }

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