0
点赞
收藏
分享

微信扫一扫

js&jquery避免报错的方法

 

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 条评论