HTML:
<input type="text" value="10" id="price-1" size="2" />
<input type="text" value="15" id="price-2" size="2"/>
<input type="text" value="20" id="price-3" size="2"/>
<input type="text" value="25" id="price-4" size="2"/>
<table>
<tr>
<td>
<select class="drop">
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
<option value="4">Test 4</option>
</select>
</td>
<td><input type="text" value="" class="cost" /></td>
</tr>
<tr>
<td>
<select class="drop">
<option value="1">Test 5</option>
<option value="2">Test 6</option>
<option value="3">Test 7</option>
<option value="4">Test 8</option>
</select>
</td>
<td><input type="text" value="" class="cost" /></td>
</tr>
</table>
JS:
$('body').delegate(".drop", "change", function() {
var end = this.value;
var price = $('#price-'+ end).val();
$('.cost').val(price);
});
这是jsFiddler:JSFIDDLER
编辑:找到解决方案!
新JS:
$('body').delegate(".drop", "change", function() {
var end = this.value;
var price = $('#price-'+ end).val();
var new_cost = $(this).parents('tr').find('.cost');
$(new_cost).val(price);
});
答案 0 :(得分:0)
解决方案:
JS:
$('body').delegate(".drop", "change", function() {
var end = this.value;
var price = $('#price-'+ end).val();
var new_cost = $(this).parents('tr').find('.cost');
$(new_cost).val(price);
});