jQuery $(“#field”) is null?

后端 未结 5 940
忘了有多久
忘了有多久 2020-12-06 05:17

I have a selectbox with month periods in it.

Here is my code:

$(function(){ 
                        $(\"#ppsub_ppterm_id\").change(function(){ 
           


        
相关标签:
5条回答
  • 2020-12-06 05:39

    chane '$' by jQuery for example:

    $("#myId") -> jQuery("#myId")

    It works

    0 讨论(0)
  • 2020-12-06 05:42

    Make sure you're running your jQuery code after the document is loaded:

    $(document).ready(function() { /* put your stuff here */ });
    

    Also make sure you have no other controls with the id "ppsub_ppterm_id" on your HTML page.

    Those are the first things I would check.

    0 讨论(0)
  • 2020-12-06 05:45

    Even if jQuery couldn't find the element, it wouldn't be null - it would be an empty jQuery object.

    Are you sure jQuery is loaded? Is it possible that another JavaScript library you're using is causing conflicts?

    0 讨论(0)
  • 2020-12-06 05:50

    Sounds like JQuery isn't loading properly. Which source/version are you using?

    Alternatively, it could be namespace collision, so try using jQuery explicitly instead of $. If that works, you may like to use noConflict to ensure the other code that's using $ doesn't break.

    0 讨论(0)
  • 2020-12-06 05:53

    you have "ppsub_ppterm_id" as a class, name, id etc...

    You need to pick ONE and select on it. There is no need for ID, NAME, CLASS to all have the same values.

    You're probably confusing the hell out of jQuery.

    <a id="ppsub_ppterm_id"> = $("#ppsub_ppterm_id")
    
    <a class="ppsub_ppterm_id"> = $(".ppsub_ppterm_id")
    
    <a name="ppsub_ppterm_id">  = $("*[name=ppsub_ppterm_id]")
    

    Pick a way and go with it, but take out all those redundant attributes.

    0 讨论(0)
提交回复
热议问题