When an element from the list is selected I want to fill the search input with the 'data-search' attribute.
我有这个标记:
<input type="text" name="search" value="" id="id_search" />
<select id="cd-dropdown" class="cd-select">
<option value="-1" selected>Choose your prize</option>
<option value="1" class="search-btn" data-search="camera">Camera</option>
<option value="2" class="search-btn" data-search="diamonds">Diamonds</option>
<option value="3" class="search-btn" data-search="spaceship">Spaceship</option>
</select>
LE:我找到了解决方案:
$("#cd-dropdown").change(function()
{
$("#id_search").val($("#cd-dropdown :selected").attr("data-search"));
});
但不幸的是不适用于 jquery 1.8.3 有没有办法让它与这个版本一起工作?