用变量替换名称属性-JQUERY

问题描述:

我正在使用select元素来更改媒体网站上的搜索类型(即按流派搜索,按艺术家搜索).

I am using a select element to change the search type on a media site (i.e. search by genre, search by artist).

我已经创建了下拉列表,并且可以通过变量获取所选的选项,但是现在我需要用variable/selected选项替换输入元素上的name属性.我已经看到了下面的代码来更改值",是否有类似这样的方法来更改输入元素上的name属性.

I have created the dropdown and can get the selected option via a variable but now I need to replace the name attribute on the input element with the variable/selected option. I have seen the below code to change the "value", is there anything like this for changing the name attribute on an input element.

$("input[name$='letter']").val("a letter");

.attr('name', 'blah')