开发者

Jquery Selectors not working

开发者 https://www.devze.com 2023-01-02 15:14 出处:网络
I use the following selector to get the value out of an input that\'s inside a table but it doesnt work properly?

I use the following selector to get the value out of an input that's inside a table but it doesnt work properly?

var kom =$("tr#1 .b input").attr(value);

and row looks a开发者_运维知识库s follow

  <tr class="numbers" id="1">
   <td class="a" align="right">1</td>
   <td class="a" align="left">Tue</td>
   <td class="b"><input class="input" type="text" title="" value=""/></td>
   <td class="c"><input class="input" type="text" title="" value=""/></td>
   <td class="d"><input class="input" type="text" title="" value=""/></td>
   <td class="e"><input class="input" type="text" title="" value=""/></td>
   <td class="f">0</td>
   <td class="g"><input class="input" type="text" title="" value=""/></td>
 </tr>

any suggestion on what i might be doing wrong any aid is greatly appreciated

regards breezer


Two problems here, first your IDs should not start with a number, use a prefix, like row1, then use .val() to get the value, like this:

var kom =$("tr#row1 .b input").val();

If you were to use .attr(), you would use it like this .attr('value'), currently it's looking for .attr(undefined). I put if in italics because you should pretty much always use .val() to get or set a value on an <input>...same goes for <select> and <textarea>.


Try putting value in quotes.


Accessing the DOM's value attribute can be a bit funky. Try this:

var kom =$("tr#1 .b input").val();


This is what you want:

var kom = $(".b input").val();


var kom =$("tr#1 .b input").attr("value")

or better

var kom =$("tr#1 .b input").val();


$("tr#1 .b input").attr("value");

Watch that you haven't enclosed value in "value".

0

精彩评论

暂无评论...
验证码 换一张
取 消