1
我有一个脚本来填充数据库中的数据,但变量我试图使用变量selected
似乎没有被使用。我的意思是Netbeans告诉我这个变量没有被使用。脚本有问题吗?JQuery未使用的变量错误
function get_child_options(selected)
{
if (typeof selected === 'undefined')
{
var selected = ' ';
}
var parentID = jQuery('#parent').val();
jQuery.ajax(
{
url: '/MyProjectName/admin/parsers/child_categories.php',
type: 'POST',
data:
{
parentID: parentID,
selected: selected
},
success: function(data)
{
jQuery('#child').html(data);
},
error: function()
{
alert("Something went wrong with the child options.")
},
});
}
jQuery('select[name="parent"]').change(get_child_options);
'var selected'在块范围之外。在'if'(typeof' – bhantol
selected已经在函数params中定义,在vard''之前移除'var''之前,像@dxcorzo在他的回答中显示的那样。 – Shanimal