如果所有必填字段都不完整,並且是使用Google Apps腳本創建的表單的一部分,我有以下JavaScript函數可阻止表單提交。請注意,#submitbutton實際上是一個常規按鈕,Google Apps腳本會強制使用嚴格的JavaScript。該腳本在Chrome上運行良好,但是當我在Safari或Firefox上測試它時,它似乎沒有運行。我是否使用僅適用於Chrome的方法?我在這裏錯過了什麼嗎?使用jQuery在Safari和Firefox中使用Javascript(嚴格)錯誤
我收到以下錯誤在Safari: Uncaught TypeError: undefined is not a function (evaluating '(1, $)('#submitbutton')')
和Uncaught Strict mode does not allow function declarations in a lexically nested statement.
火狐給出了一個類似的問題: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沒有按」 t使用google.script,但用this.parentNode.submit替換它()
任何幫助,非常感謝。
每評論:
maestro_htmlapp_bin_maestro_htmlapp.js的線84:84:360: 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]),
with firefox can you show the line'maestro_htmlapp_bin_maestro_htmlapp.js:84:360'? – tnga
@arsel,你只想要84行嗎?我將其附加到原始帖子。如果這不是你要求的,請原諒我的無知。 – LJB