HTMLInputElement没有方法'val' [英] HTMLInputElement has no method 'val'

查看:123
本文介绍了HTMLInputElement没有方法'val'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在循环表格中的单元格。每个单元格都有一个文本框,并且我想要将文本框的值推送到数组中。

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 dothing() {
        var tds = $('#'+selected+' td');
        var submitvals = new Array();
        tds.each(function(i) {
            var val = $(this).children('input')[0].val();
            submitvals.push(val);
        });
    }

更多的函数,但这都是相关的。出于某种原因,当我运行此代码时,我得到HTMLInputElement没有方法'val'。我认为输入元素应该在jQuery中有一个 val()方法来获取值,所以这没有任何意义。我错过了什么,或者做错了什么?

Theres more to the function, but this is all that is relevant. For some reason, when I run this code, I get "HTMLInputElement has no method 'val'." I thought that input elements were supposed to have a val() method in jQuery that got the value so this makes no sense. Am I missing something, or doing it wrong?

推荐答案

val()是一个jQuery方法。 .value 是DOM元素的属性。使用 [0] .value .eq(0).val() ....

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

这篇关于HTMLInputElement没有方法'val'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆