【发布时间】:2015-09-18 17:32:20
【问题描述】:
如果所有必填字段都不完整并且是我使用 Google Apps 脚本创建的表单的一部分,我有以下 javascript 函数可以阻止表单提交。请注意,#submitbutton 实际上是一个常规按钮,Google Apps 脚本强制使用严格的 javascript。该脚本在 chrome 上运行良好,但是当我在 Safari 或 Firefox 上测试它时,它似乎没有运行。我是否使用仅适用于 Chrome 的方法?我在这里遗漏了什么吗?
我在 Safari 中收到以下错误:
Uncaught TypeError: undefined is not a function (evaluating '(1, $)('#submitbutton')') 和 Uncaught Strict mode does not allow function declarations in a lexically nested statement.
Firefox 给出了类似的问题:Uncaught in strict mode code, functions may be declared only at top level or immediately within another function 2699307207-maestro_htmlapp_bin_maestro_htmlapp.js:84:360 和 Uncaught TypeError: $ is not a function
<script type="text/javascript">
$('#submitbutton').on('click', function() {
$(this).val("Submitting...");
//check for required fields
var emptyFields = $('[required]').filter(function() {
$(this).removeClass("warning");
if ($(this).val().length === 0){
$(this).addClass("warning")
return true
} else {
return false
}
});
if (emptyFields.length === 0) {
$(this).prop('disabled', true);
document.getElementById('incompleteWarning').style.display = 'none';
document.getElementById('bePatient').style.display = 'inline';
google.script.run.withSuccessHandler(fileUploaded).uploadFiles(this.parentNode);
} else{
$(this).val("Submit Application")
document.getElementById('incompleteWarning').style.display = 'inline';
document.getElementById('incompleteWarning').style.color = 'red';
}
});
</script>
jsfiddle 在这里:https://jsfiddle.net/hofresre/
请注意,jsfiddle 不使用 google.script,而是将其替换为 this.parentNode.submit()
非常感谢任何帮助。
每厘米:
maestro_htmlapp_bin_maestro_htmlapp.js:84:360 的第 84 行:
function ys(a){for(var b=[],c=0;c<a.length;++c){var d=a[c];b[c]=Mn(d)?(new String(d)).toString():d}return b}var As=[vh,"[object Object]"];var Bs=["alert",ts(function(a){return alert(a)},16,[4]),"confirm",ts(function(a){return confirm(a)},16,[4]),"prompt",ts(function(a,b){return prompt(a,b)},16,[4,4])];var Cs=window.console&&window.console.error?function(a){window.console.error(a)}:void 0,Ds=window.console&&window.console.info?function(a){window.console.info(a)}:void 0,Es=window.console&&window.console.log?function(a){window.console.log(a)}:void 0,Fs=window.console&&window.console.warn?function(a){window.console.warn(a)}:void 0,Gs=["console.debug",ts(window.console&&window.console.debug?function(a){window.console.debug(a)}:void 0,16,[4]),"console.error",ts(Cs,16,[4]),"console.info",ts(Ds,16,[4]),
【问题讨论】:
-
用firefox你能告诉我们
maestro_htmlapp_bin_maestro_htmlapp.js:84:360这个行吗? -
@arsel,你只想要第 84 行吗?我把它附在原帖上。如果这不是您的要求,请原谅我的无知。
标签: javascript jquery html google-apps-script safari