在
JQuery中给出一个带有多个选项的select.
$select = $("");
$select.append("Jason") //Key = 1
.append("John") //Key = 32
.append("Paul") //Key = 423
如何存储和检索密钥?
ID可能是一个好的地方,但如果我有多个select的共享值(和其他场景),则不能保证唯一.
谢谢
并本着TMTOWTDI的精神.
$option = $("");
$select = $("");
$select.addOption = function(value,text){
$(this).append($("").val(value).text(text));
};
$select.append($option.val(1).text("Jason").clone())
.append("John")
.append($("").val(423).text("Paul"))
.addOption("321","Lenny");