HTMLInputElement has no method 'val'

前端 未结 5 920
走了就别回头了
走了就别回头了 2021-02-05 02:28

I\'m looping through cells in a table row. each cell has a text box in it, and I want to take the value of the text box and push it onto an array.

function dothi         


        
相关标签:
5条回答
  • 2021-02-05 02:40

    What I don't understand, is why none of the suggested syntaxes on this or other questions similar to this seem to work for me. I had to do trial and error and eventually had to use:

    MySelectElement.value = x;

    It also didn't help that the Visual Studio Intellisense suggestions offer a whole other range of unworking method names, such as ValueOf().

    0 讨论(0)
  • 2021-02-05 02:50

    .val() is a jQuery function, not a javascript function. Therefore, change:

    var val = $(this).children('input')[0].val()
    

    To:

    var val = $(this).children('input:eq(0)').val()
    
    0 讨论(0)
  • 2021-02-05 02:53

    val() is a jQuery method. .value is the DOM Element's property. Use [0].value or .eq(0).val()....

    0 讨论(0)
  • 2021-02-05 03:00

    .val() is a jquery method. Using [0] returns the DOM element, not the jquery element

    var val = $(this).children('input:first').val();
    
    0 讨论(0)
  • 2021-02-05 03:01
    function dothing() {
        var tds = $('#'+selected+' td');
        var submitvals = new Array();
        tds.each(function(i) {
            var val = $($(this).children('input')[0]).val();
            submitvals.push(val);
        });
    }
    
    0 讨论(0)
提交回复
热议问题