Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
993 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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();

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...