以下是js,当我尝试保存它时,它显示“元素的内容必须包含格式良好的字符数据或标记。”错误,请帮助我解决这个问题
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script>
(function(){
if ($('html').hasClass('csstransforms3d')) {
var foldingList = $('.folding'),
foldingListHeight = $('.folding').height();
topElemOffset = foldingList.offset().top,
**===========================================^
lint warning: multiple statements separated by commas (use semicolons?)**
// Function responsible for unfolding the list
unfold = function(){
setTimeout(function(){
if (foldingList.hasClass('folded')){
foldingList.removeClass('folded');
return;
}
}, 500);
}
// Fold/Unfold the list
$('.connect').on("click",function(){
**==^
lint warning: missing semicolon**
foldingList.toggleClass('folded');
})
// If needed, unfold the list right away
if (topElemOffset <= $(window).height() - foldingListHeight)
unfold();
**===^
lint warning: block statement without curly braces**
// Check whether to unfold the list when scrolling/resizing
$(window).on("scroll resize", function(){
var th = $(this);
if (th.scrollTop() + th.height() - foldingListHeight >= topElemOffset)
unfold();
**====^
lint warning: block statement without curly braces**
})
}
})()
</script>
答案 0 :(得分:0)
错误信息非常清楚。
topElemOffset = foldingList.offset().top; // ; instead of ,
...
$('.connect').on("click",function(){
foldingList.toggleClass('folded');
}); // semicolon was mising
...
//write if-statements like this
if(expression){
//dowork
}