【发布时间】:2012-04-22 02:47:05
【问题描述】:
我有一个实体框架生成的表,其中包含我需要更改的 td 值。我需要逐行执行此操作,因为我需要插入一组单选按钮,但每行按钮都需要一个唯一的名称。
基本上,我需要根据 td 中 id 为“Rate”的文本值设置一组按钮的选中值,并在我从中获取值后删除现有文本。
我的桌子是这样的,
<table id="IndexTable">
<tr>
<th>CoffeeID </th>
<th>Degree </th>
<th>Weight </th>
<th>Profile </th>
<th>UsageInfo </th>
<th>Comments </th>
<th>AmbientTemp </th>
<th>Rating </th>
<th>WeightDeducted </th>
<th>Selected </th>
<th>ProfileID </th>
<th>ProfileStart </th>
</tr>
<tr>
<td>1 </td>
<td>1 </td>
<td>3 </td>
<td>9 </td>
<td>Filter Brew </td>
<td>Perfecto!! </td>
<td>55 </td>
<td id="Rating">4.25 </td>
<td>1 </td>
<td>4 </td>
<td>34 </td>
<td>1 </td>
</tr>
<tr>
<td>3 </td>
<td>15 </td>
<td>99 </td>
<td>87 </td>
<td>Espresso </td>
<td>WTF </td>
<td>99 </td>
<td id="Rating">4.5 </td>
<td>5 </td>
<td>3 </td>
<td>66 </td>
<td>4 </td>
</tr>
而我的脚本如下。
$("tr").each(function() { //get all rows in table
var str = $("text[id=Rating]").val(); //assign text with matching id to str ---doesn't work
$("td").each(function() { //get all tds in current row
var newStr = ("#Rating").text; //assign text in td with id Rating to newStr ---- doesn't work
alert(newStr); // fires undefined for each td in table?
//This is where I want to insert radio buttons and assign the one with the value of the Rating td to checked.
});
});
这只是最新的,我浏览了整个网站,但我所看到的一切都没有涉及从特定行的特定列获取值、更改值以及对每一行重复/表中的列。 我来自 db 背景,这真的很简单,这很令人沮丧。
【问题讨论】:
-
你打算把单选按钮放在哪里?
-
ID 在 DOM 中应该是唯一的。一个 html 文档中不能有多个
id="Rating"。 -
我想将 td 中的文本替换为带有单选按钮的评级“指出的类”,并检查与该值匹配的那个。
标签: jquery html entity-framework-4 html-table