$('#id').value is undefined

前端 未结 3 1926
北海茫月
北海茫月 2021-01-24 06:06

I am having trouble with trying to check the length of a field and set a value based on the result. Using firebug with firefox I keep getting the error \'elUsername\' is not def

相关标签:
3条回答
  • 2021-01-24 06:06

    Change those variables to this:

    var elUsername = $('#usernameInput').val();
    
    0 讨论(0)
  • 2021-01-24 06:10

    try this

    var elUsername = $('#usernameInput').val();
    

    Instead of

    var elUsername = $('#usernameInput').value;
    
    0 讨论(0)
  • 2021-01-24 06:31

    You're trying to use a native JavaScript property on a jQuery object. Use :

    var elUsername = $('#usernameInput').val();
    

    or

    var elUsername = document.getElementById('usernameInput').value;
    

    or the slightly less obvious, but still valid:

    var elUsername = $('#usernameInput')[0].value;
    var elUsername = $('#usernameInput').get(0).value;
    
    0 讨论(0)
提交回复
热议问题