![](/img/trans.png)
[英]Populate the select field from collection and filter according to the selected value in meteor
[英]jQuery - Change id according to the value selected from the select field
我正在嘗試使用JS函數更改select
字段的ID,請查看我的HTML和JS代碼。
HTML:
<select name="cat-parent" id="change_id();"> <option selected="selected" value=""></option> <option value="category-2">Category 2</option> <option value="category-3">Category 3</option> <option value="category-4">Category 4</option> <option value="category-2">Category 2</option> <option value="category-1">Category 1</option> </select>
JS:
function change_id(){ var idSuffix = jQuery(this).val(); return 'example' + idSuffix; }
您需要綁定change
事件處理程序。
$('[name=cat-parent]').on('change', function() {
$(this).attr("id", 'example' + $(this).val());
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.