js&jquery避免报错的方法

寒羽鹿

关注

阅读 38

2023-02-15

 

CreateTime--2016年12月8日15:28:40
Author:Marydon
js&jquery规避报错信息的两种方式

<script type="text/javascript">
$(function() {
/*方法一:捕获异常*/
try {
$('div[id=TreeContainer]').each(function(){
$(this).width($('#LeftPage').width());
});
} catch (e) {}
/*方法二:加上非空校验*/
if ($('div[id=TreeContainer]')) {
$('div[id=TreeContainer]').each(function(){
$(this).width($('#LeftPage').width());
});
}
});
</script>

 

 



精彩评论(0)

0 0 举报