我确定这是个愚蠢的问题,但我不知道答案。
我有一个以这种方式填充的字段
<div class="field">
<%f.label :client_id %>
<%= f.select :client_id,
options_for_select(Client.all.map{ |p| [p.appointment_record, p.id]}), # your options for this select box
include_blank: 'Select Client'
%>
所以当我得到
clients = $('#appointment_client_id').html()
这是
<option value="">Select Patient First, Please</option>
<option value="1">Guy, First - Programmer</option>
<option value="2">Guy, Second - Code Monkey</option>
我想要的是更改这些值标签。该列表是动态生成的。
如何更改 .each 循环中的值标签以使其保持不变?
最佳答案
根本不清楚您想要更改什么或从什么来源更改。
假设你想改变<option>
您可以使用的值 val(function)
循环遍历集合。函数的参数是索引和当前值
示例:
$('#appointment_client_id').children(':gt(0)').val(function(i, currVal){
return currVal ? currVal * 10 :'';
});
关于Javascript - 在每个循环中更改 html 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37775316/