【发布时间】:2014-08-12 05:07:53
【问题描述】:
我正在尝试js:
$('a[data-select="more-options"]').click(
function () {
$('select')
.append($("<option></option>")
.attr("one more additional and long option",3)
.text("3333333333"));
}
);
在 HTML 上
<span id="dropdown">A
<select>
<option>this is option 1</option>
<option>This is option 2</option>
</select> list<br>
</span>
<a data-select="more-options" href="#">Add long option to the select</a>
但我没有得到任何结果(或错误)。
【问题讨论】:
-
“一个额外的长选项”是属性吗?
-
在 Chrome 35 中执行代码时确实出现错误:未捕获的 InvalidCharacterError:无法在“元素”上执行“setAttribute”:“另一个额外的长选项”不是有效的属性名称.
标签: javascript jquery