1

可能是一项简单的任务,但我找不到可行的解决方案?

我需要将所选选项中的类值添加到相对 TR:

<table>
<tr class="odd views-row-first">
<td class="views-field views-field-website-id">1</td>
<td class="views-field views-field-changed">1349422708</td>
<td class="views-field views-field-created">1349422708</td>
<td class="views-field views-field-title">Double field</td>
<td class="views-field views-field-field-rules-conditional  views-field-editablefield">
<div id="editablefields-field-rules-conditional" class="editablefield-item">

<select id="edit-field-rules-conditional-0-field-rules-conditional-und" name="field_rules_conditional[0][field_rules_conditional][und]" class="form-select">
<option value="_none">- None -</option>
<option value="green">green</option>
<option value="red">red</option>
<option value="blue" selected="selected">blue</option>
</select>

</div>         
</td>
</tr>
</table>​

我想拥有的:

<tr class="odd views-row-first blue">
4

1 回答 1

1

index功能将解决您的问题。请尝试以下操作:

  $("#edit-field-rules-conditional-0-field-rules-conditional-und option").click(function(){
         var index = $("option",$("#edit-field-rules-conditional-0-field-rules-conditional-und")).index($(this));
        var $td = $("#tableId tr:eq(0) td:eq(" + index + ")");            
        $td.addClass($(this).attr("value"));
    });

编辑:也给你的表一个 ID。我在示例中使用了“tableId”,所以用你想要的替换。

于 2012-11-25T08:31:55.637 回答