Firstly I have a form, this is part from my form code:

<td class="td1" width="15%" id="td00">abc</td>
<td class="td1" width="15%" id="td01">efg</td>

from jQuery, I want pass the value of the td to my server via ajax.

If I use:

var name=$('#td00').val();

I get an empty value, if this is not a table but a text input, I can get value like this, but now it not working in table.

有帮助吗?

解决方案

You need to use .text() or .html()

var name=$('#td00').text();
  • .html() will get the html content of the element
  • .text() will get the text content of the element
  • .val() works for <input/> <select/> <textarea/> .It gets the property value of those elements.

Documentation

  1. .Val()

  2. .text()

  3. .html
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top