Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选项[options.length]不起作用_Javascript_Jquery_Html_Attributes - Fatal编程技术网

Javascript 选项[options.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_

我有jquery代码,可以获取值并在数据库中更新它们。问题是它现在似乎不起作用

它说:uncaughttypeerror:无法读取未定义的属性“length”

以下是部分代码:

$('#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约翰尼