0
我有我的網頁上有很多的腳本:JavaScript錯誤處理
例子:
<script>
window.addEvent('Updated', function(data) {
/*I'm using a mootools javascript framework and my string below contain an error:
Uncaught TypeError: Cannot call method 'empty' of null*/
var container = document.getElement('cart_contents_data');
container.empty();
});
</script>
此錯誤打破了所有其他代碼(腳本塊)。 我正在尋找隔離腳本塊(彼此)的方式。
我試過這樣的事情:
<script>
try {
window.addEvent('Updated', function(data) {
/*I'm using a mootools javascript framework and my string below contain an error:
Uncaught TypeError: Cannot call method 'empty' of null*/
var container = document.getElement('cart_contents_data');
container.empty();
});
} catch(err) {console.log(err)}
</script>
但這種方法並不能幫助我。 謝謝。
我知道你的代碼工作。但我需要解決方案來隔離模塊代碼。可能嗎? – user889349
你是什麼意思的模塊。你使用requirejs或任何AMD模塊框架的Javascript?如果是這樣,請將其添加到您的問題(使用編輯按鈕) –
沒有隻是結構。 – user889349