为什么.val()始终为空(jQuery)? [英] Why .val() is always empty (Jquery)?

查看:554
本文介绍了为什么.val()始终为空(jQuery)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的输入法有问题.

这是我的html/php代码:

here's my html/php code :

$dotation = ($ig["dotation"]) ? $ig["dotation"]: '<input type="text" class="datepickerIG" name="igDota" size="8" value="test"/>';
            $bo .= '<tr style="background-color: black;">
                     <td class="dot">' . $dotation . '</td>
                     <td class="modif" ref="' . $ig["id"] . '"><a href="#">Modifier</a></td>

这是我的js代码:

        var dot_cha = $(this).parent().find('.dot').val();

我的问题是,为什么var dot_cha始终为空? 当我使用.html替代.val时,我没错,那我的错误在哪里?

my question is, why var dot_cha is always empty ?! when I use .html insteed of .val, I get the right so, where's my error ?

谢谢.

推荐答案

.val()获取输入元素的value属性. ".dot"是td,没有值属性.

.val() grabs the value attribute of a input-element. ".dot" is a td and doesn't have a value-attribute.

您希望dot_cha到底是什么?如果您要输入的内容,则可以使用.

What exactly is it you want dot_cha to be? If its the input you are after, this would work.

$(this).parent().find('.datepickerIG').val();

如果是td的文本,则.html()或.text()会为您提供.

If it is the text of the td .html() or .text() will give you this.

这篇关于为什么.val()始终为空(jQuery)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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