私はPython/Djangoで書かれたWebアプリケーションで作業しています。特に、フォーム上のユーザーが入力した '日付'の値が保持されていないバグに取り組んでいます(つまり、ページを更新した場合、日付フィールドはユーザーの変更前に保持されていた値に戻ります)それ)。JavaScript-Uncaught SyntaxError:予期しないトークン) - 余分な ')'が表示されない
フォームのこの値の変更をリッスンし、変更が検出されるたびに新しい値を保存するために、このページのHTMLファイルにJS関数を追加しました。
私が追加した機能 - 新しい値を入力してページを更新すると、入力した値が、保持していた元の値ではなく、デフォルトでフィールドに表示されます。
(index):3876 Uncaught SyntaxError: Unexpected token)
私は自分のアプリケーションに加えた変更のみが.html
に次の関数を追加している:私は私のブラウザでページを更新するとただし
$(document).on('change', '#id_date_received', function messageDepositPaid()){
console.log("document.on('change') called on id_date_received in concept.html ")
if (window.confirm("Would you like to send an email confirming we have received a deposit?")) {
console.log("'if(window.confirm)' statement entered in concept.html JS... ")
var date = $(this).val()
if (date){
date = date.split('/')
var new_date = [];
new_date = new_date.concat(date[2]).concat(date[1]).concat(date[0]);
new_date = new_date.join('-');
}
if (new_date != $(this).data('original-value')){
// CDI fee date has been changed from nothing to something
console.log("It's changed")
// Set the original-value so it won't send multiple times
$(this).data('original-value', new_date) //ERF(24/11/2016 @ 1700) This line should be copying the value of new_date to the 'original-value', so original value should now hold the new date...
//$(this).data('original-value') = new_date
// Send email to relevant people
var url="{% url 'comms:open_email_template' project.id %}?template=5"
console.log('Url', url)
$.post(url)
.done(function(response){
console.log('Email sent')
})
// ERF(28/11/2016 @ 1400) Set value of 'date' to the value of 'new_date':
date = new_date
}
}
/*} */
else{
console.log("'else' of 'if(window.confirm)' statement entered in concept.html JS... ")
var date = $(this).val()
if (date){
date = date.split('/')
var new_date = [];
new_date = new_date.concat(date[2]).concat(date[1]).concat(date[0]);
new_date = new_date.join('-');
console.log("Value of date in if(date): ", date)
}
if (new_date != $(this).data('original-value')){
//console.log("Value of this.project.date_received: ", this.project.date_received)
console.log("Value of date: ", date)
// CDI fee date has been changed from nothing to something
/*ERF(28/11/2016 @ 0935) Fee date was not necessarily nothing- need to change its value when it had a date
previously stored in it too...
Print the values of 'new_date' and 'original-value' here. */
console.log("Value of new_date: ", new_date)
console.log("Value of original-value: ", this.data)
console.log("It's changed")
// Set the original-value so it won't send multiple times
$(this).data('original-value', new_date) /*ERF(28/11/2016 @ 0950) This line isn't actually setting the original value to the value of 'new_date'...
Set the value of 'id_date_received' to the 'new_date'
Need to set the date_received attribute of the project/ presentation object deposit to this too. */
id_date_received = new_date
console.log("Value of id_date_received: ", id_date_received)
date_received = new_date
console.log("value of date_received: ", date_received)
// Send email to relevant people
var url="{% url 'comms:open_email_template' project.id %}?template=5"
console.log('Url', url)
$.post(url)
.done(function(response){
console.log('Email sent')
})
// ERF(28/11/2016 @ 1400) Set value of 'date' to the value of 'new_date':
date = new_date
}
}
}
、機能が動作します。
しかし、何らかの理由で、上記のキャッチされていない構文エラーが発生しています。
私はこの機能を何度も再読み込みしましたが、問題の原因を特定することはできません)
。
実際に構文エラーがあった場合、ページが正しく表示されないため、または関数呼び出しの1つがそれを壊すでしょうか?
コンソールに間違って表示されている可能性はありますか?実際に何かを壊してしまっても、現時点では動作していないものは見えませんが、これを解決するまで、ライブバージョンに変更をコミットしたくはありません。
私が削除した場合上記の関数をHTMLファイルから読み込み、ページをリフレッシュするとコンソールにこの構文エラーが表示されなくなりましたが、私は余分な)
がある場所、または間違った場所に1つあります...
誰でもお手伝いできますか?どうにか私のコンソールをリフレッシュする必要がありますか?私はウェブページを閲覧するためにChromeを使用しています。
'/ * * /}' 'if'間と' else'ブロックを削除してください関数の参照でなければなりません。私が見る他のことは、あなたのコードで ';'にもっと注意を払わないということです。 – ettanany
私はそれを削除しようとしましたが、明らかに、実際には何の違いもありませんでした。これはコメントされたコードです...私はそれらを使用する必要がありますか? – someone2088