i want to add javascript in my html form modal. but i got error "uncaught referenceError: $ is not defined" when i define count variable.
So ,how can i resolve this question.
<div class="modal"> <form id="multiform"> <script rel="javascript" type="text/javascript" href="/static/js/jquery.min.js"> var count=$('select#ip option:selected').length; alert(count); /*code more*/ </script> </form> </div>
There are 3 mistakes
src
instead of href
. src
to a script
tag, then script inside that tag will be ignored . body
tag or in head
tag. Demo
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="modal"> <form id="multiform"> </form> </div> <script> var count = $('select#ip option:selected').length; alert(count); </script>
Try this. you are using href insted of src
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="modal"> <form id="multiform"> <script type="text/javascript"> var count=$('select#ip option:selected').length; alert(count); /*code more*/ </script> </form> </div>
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.