Javascript 选项[options.length]不起作用
我有jquery代码,可以获取值并在数据库中更新它们。问题是它现在似乎不起作用 它说:uncaughttypeerror:无法读取未定义的属性“length” 以下是部分代码:Javascript 选项[options.length]不起作用,javascript,jquery,html,attributes,Javascript,Jquery,Html,Attributes,我有jquery代码,可以获取值并在数据库中更新它们。问题是它现在似乎不起作用 它说:uncaughttypeerror:无法读取未定义的属性“length” 以下是部分代码: $('#response_title').val(''); $("#response_new_enter").hide(); $("#response_own_enter").show(); img.attr("src","images/add_btn.png"); var options = $('#response_
$('#response_title').val('');
$("#response_new_enter").hide();
$("#response_own_enter").show();
img.attr("src","images/add_btn.png");
var options = $('#response_').attr('options');
options[options.length] = new Option(response_title, r, true, true); // error comes up in this line
alert("New Response Added Successfully.");
$("#myspan").html("New Response Added Successfully.");
$("#myspan").show();
setTimeout(function(){ $('#myspan').fadeOut(1000); }, 10000);
options
不是一个属性,而是一个要尝试的属性
var options = $('#response_').prop('options');
var options = $('#response_')[0].options; //or
但是您可以使用jQuery创建如下选项
$('<option />',{text: response_title, value: r, selected: true}).appendTo('#response_');
$(“”,{text:response_title,value:r,selected:true});
选项
不是一个属性,而是一个要尝试的属性
var options = $('#response_').prop('options');
var options = $('#response_')[0].options; //or
但是您可以使用jQuery创建如下选项
$('<option />',{text: response_title, value: r, selected: true}).appendTo('#response_');
$(“”,{text:response_title,value:r,selected:true});
请共享相关的HTML代码,也请共享相关的HTML代码,以便代码的其余部分保持原样?对吗@Arun P Johnyand那么剩下的代码保持原样了吗?对吗@阿伦P约翰尼