我有这个javacsript函数,它一直工作正常,但后来我添加了一些代码,除非我注释掉该代码,它给出了错误:
ReferenceError: updateListingForm is not defined
Run Code Online (Sandbox Code Playgroud)
完整的代码是:
function updateListingForm(type) {
if (jQuery('#voucher_value').length){
var voucher_value = jQuery('#voucher_value').val();
} else {
var voucher_value = null;
}
if (jQuery('#category_id')val().length > 0 && isNaN(jQuery('#category_id').val()) == false) {
var category_id = jQuery('#category_id').val();
} else {
var category_id = 0;
}
var loadUrl = relative_path + 'ajax_files/change_listing_type.php';
var dataObject = { type: type, category_id: category_id, voucher: voucher_value }
getAjaxData(loadUrl, dataObject, 'GET', 'json')
.done(function(response) {
console.log(response);
// Add/remove the listing field stuff
jQuery('#listing_type').html(response.listing_type);
// Input addl cat fee
jQuery('#addl_cat_fee').html(response.addl_cat_fee);
})
.fail(function() {
alert('There seems to have been a problem changing the listing type; please contact us if this continues to occur.');
});
// End
}
Run Code Online (Sandbox Code Playgroud)
如果我注释掉下面的代码,它可以正常工作:
if (jQuery('#category_id')val().length > 0 && isNaN(jQuery('#category_id').val()) == false) {
var category_id = jQuery('#category_id').val();
} else {
var category_id = 0;
}
Run Code Online (Sandbox Code Playgroud)
但是为了让它工作正常,我显然需要添加这一行,如果注释掉上述内容:
var category_id = 0;
Run Code Online (Sandbox Code Playgroud)
我的代码有什么问题导致它出现此错误?
jQuery('#category_id')val()是语法错误.你想要的jQuery('#category_id').val().
您会看到错误,updateListingForm is not defined因为语法错误会停止解析器并中止函数的创建.
尝试使用该函数时,会发生函数未定义的错误.从解析器尝试创建函数时,您还应该在控制台中看到先前的错误:在Chrome,Firefox或IE中.该错误应该指向问题的确切线.Uncaught SyntaxError: Unexpected identifierSyntaxError: missing ) after conditionExpected ')'
| 归档时间: |
|
| 查看次数: |
1372 次 |
| 最近记录: |