Why .val() is always empty (Jquery)?

2019-08-26 19:46发布

I have a problem with an Input.

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>

here's my js code :

        var dot_cha = $(this).parent().find('.dot').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 ?

Thanks.

7条回答
我想做一个坏孩纸
2楼-- · 2019-08-26 20:28

I would say that the problem is a <td> doesnt have a value, it contains HTML.

That would be why .html works and .val doesnt.

You use .val on inputs that have values, but <td> is not an input its just a HTML tag.

查看更多
登录 后发表回答