我可以通过googlechrome控制台正常运行,而无需重新加载页面
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
jQuery('#addressInput').val(getParameterByName('addressInput'));
jQuery('#addressSubmit').click();
然而,在我使用这种结构上传我的.js文件后,我无法运行它。
jQuery(document).ready(function() {
getParameterByName(name);
jQuery('#addressInput').val(getParameterByName('addressInput'));
jQuery('#addressSubmit').click();
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
我收到此错误
Uncaught SyntaxError: Unexpected token function
任何想法如何才能让它正确运行?
提前致谢
答案 0 :(得分:1)
jQuery(document).ready(function() {
jQuery('#addressInput').val(getParameterByName('addressInput'));
jQuery('#addressSubmit').click();
}); // <-- close the bracket
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}