使用 javascript onchange 更改下拉列表的名称

Changing the name od a dropdown using javascript onchange

您好,我需要根据列表中 select 编辑的内容更改下拉框的名称。

<form  name="dofilter" method="post" action="<%=site_url%>/product">
    <select name="ff" onchange="form.submit();">
        <option value="">--</option>
        <option value="brut">brut</option>
        <option value="Moet"> Moet</option>
    </select>
</form>

如果选项 brut 是 selected 我需要 select 名字是 FK 和 如果选项 Moet 是 selected 我需要 select 名称是 FF

请帮忙

我是这样做的:

$("form > select").change(function () {
    $(this).parent().attr("name", $(this).find("option:selected").attr("id"));
});

Here is the JSFiddle demo.

您可以通过检查元素来查看名称的即时变化。