这只是附加与jQuery选择选项 [英] select option which were just appended with jquery
本文介绍了这只是附加与jQuery选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据一个AJAX查询我追加了一些选项列表。
为(VAR I = 0; I< options.length;我++){
VAR数据=选项[I]
VAR选项= $('<选项ID =mySelectElementOption_'+数据['身份证'] +'VALUE =+数据['值'] +'>'+数据['值'] +' < /选项>');
$('#mySelectElement')追加(可选)。
}
现在,当用户我想就刚才附加选项选择页面上的交互,我尝试以下(这两种可能性不为我工作):
$('#mySelectElementOption_'+ id)的.attr('选择','选择');
和
VAR选项=的document.getElementById('mySelectElementOption_'+ id)的;
option.selected = TRUE;
所以我坚持,因为我不知道该如何选择我的选择。你有什么想法(S)我怎么能解决这个问题?
谢谢!
P.S:当我尝试在谷歌浏览第二种可能,它完美的作品。
问候,约瑟夫
解决方案
VAR选择采用= {成功:功能(数据)
{
//做的一切在这里第一次追加之前,
//包括添加事件绑定
}}$阿贾克斯(选)
Based on an AJAX query I appended some options to a list.
for(var i = 0; i < options.length; i++) {
var data = options[i];
var option = $('<option id="mySelectElementOption_' + data['id'] + '" value="' + data['value'] + '">' + data['value'] + '</option>');
$('#mySelectElement').append(option);
}
Now when the user interacts on the page i want to select on of the just appended options and i tried the following (both possibilities don't work for me):
$('#mySelectElementOption_' + id).attr('selected', 'selected');
and
var option = document.getElementById('mySelectElementOption_' + id);
option.selected = true;
So I'm stuck, because I don't know how to select my option. Do you have any idea(s) how I can solve this? Thanks!
P.S.: When I try second possibility in Google Chrome it works perfectly.
Greetings, Joseph
解决方案
var opts = {
success: function(data)
{
//do everything here first before appending it,
//including adding event bindings
}
}
$.ajax(opts)
这篇关于这只是附加与jQuery选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文