jquery选择器获得唯一ID

时间:2013-04-05 11:10:33

标签: javascript jquery css-selectors

我正在尝试通过选择具有唯一ID的tr元素来获取行内容。

这是我到目前为止所做的,我对此很新,并且真的不确定为什么这不起作用。

var value = $('tr#'+idd).find('input[type=text]').map(function() { return $(this).attr("value"); }).get();

我已尝试更改ID,因此它不是唯一的,它确实会接收数据。所以只是混淆了为什么这句话没有。

感谢任何帮助

while ($record = mysql_fetch_array($entrys))
{
    echo "<tr id='" . $record['id'] . "'>";
    echo "<td>" . "<input type='text' id='id' name='id' value=" . $record['id'] . " ></td>";
    echo "<td>" . "<input type='text' id='make' name='make' value=" . $record['make'] . " ></td>";
    echo "<td>" . "<input type='text' id='fuel' name='fuel' value=" . $record['fuel'] . " ></td>";
    echo "<td>" . "<input type='text' id='transmission' name='transmission' value=" . $record['transmission'] . " ></td>";
    echo "<td>" . "<input type='text' id='size' name='size' value=" . $record['size'] . " ></td>";
    echo "<td>" . "<input type='text' id='doors' name='doors' value=" . $record['doors'] . " ></td>";
    echo "<td>" . "<input type='hidden' id='hidden' name='hidden' value=" . $record['id'] . " ></td>";
    echo "<td>" . "<button name='update' onclick=edit('".$record['id']."') >Edit</button>";
    echo "<td>" . "<button id='delete' name='delete' onclick=del('".$record[id]."') value=" . $row . " >Delete</button>  </td>";
    echo "</tr>";

}
echo "</table>";

2 个答案:

答案 0 :(得分:0)

试试这个:

return $(this).val();

答案 1 :(得分:0)

你的最后一行:

echo "<td>" . "<button id='delete' name='delete' onclick=del('".$record[id]."') value=" . $row . " >Delete</button>  </td>";

.$record[id]." - 应该像其他人一样.$record['id']."