jquery selector can't read from hidden field

后端 未结 6 1230
孤独总比滥情好
孤独总比滥情好 2020-12-16 15:06

(answers aggregated into another question)

The following jquery 1.3.2 code works:



        
6条回答
  •  情深已故
    2020-12-16 15:48

    This may be more of an issue with the console. I ran a test and it seems to still grab the instance of the element. I can't exactly tell what you are trying to do here.

    If you are just trying to validate wether the object was found check the length property

    console.log( $('#xid').length );
    

    If you are trying to get the value of the field then use the val method

    console.log( $('#xid').val() );
    

    Finally, its possible that in your solution the DOM hasn't fully loaded yet. Make sure you are wrapping your logic inside a document.ready call.

    $(document).ready(function() {
        console.log( $('#xid').val() );
    });
    

提交回复
热议问题