-2
我是新來的網頁設計。我試圖在下面的JavaScript代碼中結合所有的功能,但最終沒有一個工作了。我用檢查工具檢查它顯示語法錯誤,但我不知道我做錯了什麼。功能之前的逗號導致語法錯誤
$(document).ready(function() {
{
$('.img-zoom').hover(function() {
{
$(this).addClass('transition');
},
function() {
$(this).removeClass('transition');
}
});
{
$('[data-toggle="tooltip"]').tooltip();
});
{
var date_input = $('input[name="date"]'); //our date input has the name "date"
var container = $('.bootstrap-iso form').length > 0 ? $('.bootstrap-iso form').parent() : "body";
var options = {
format: 'mm/dd/yyyy',
container: container,
todayHighlight: true,
autoclose: true,
};
date_input.datepicker(options);
});
{
// Configure/customize these variables.
var showChar = 50; // How many characters are shown by default
var ellipsestext = "...";
var moretext = "Show more >";
var lesstext = "Show less";
$('.more').each(function() {
var content = $(this).html();
if (content.length > showChar) {
var c = content.substr(0, showChar);
var h = content.substr(showChar, content.length - showChar);
var html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
$(this).html(html);
}
});
$(".morelink").click(function() {
if ($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext);
} else {
$(this).addClass("less");
$(this).html(lesstext);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
});
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$('nav').addClass('stuck');
} else {
$('nav').removeClass('stuck');
}
});
$(".destination-menu li").sort(asc_sort).appendTo('.destination-menu');
//$("#debug").text("Output:");
// accending sort
function asc_sort(a, b) {
return ($(b).text()) < ($(a).text()) ? 1 : -1;
}
// decending sort
function dec_sort(a, b) {
return ($(b).text()) > ($(a).text()) ? 1 : -1;
}
//amChart.com for interactive map
var map = AmCharts.makeChart("mapdiv", {
type: "map",
theme: "dark",
projection: "mercator",
panEventsEnabled: true,
backgroundColor: "transparent",
backgroundAlpha: 1,
zoomControl: {
zoomControlEnabled: true
},
dataProvider: {
map: "worldHigh",
getAreasFromMap: true,
areas: [{
"id": "AT",
"showAsSelected": true
}, {
"id": "AZ",
"showAsSelected": true
}, {
"id": "CZ",
"showAsSelected": true
}, {
"id": "DE",
"showAsSelected": true
}, {
"id": "ES",
"showAsSelected": true
}, {
"id": "FR",
"showAsSelected": true
}, {
"id": "GB",
"showAsSelected": true
}, {
"id": "IE",
"showAsSelected": true
}, {
"id": "IT",
"showAsSelected": true
}, {
"id": "NO",
"showAsSelected": true
}, {
"id": "VA",
"showAsSelected": true
}, {
"id": "CA",
"showAsSelected": true
}, {
"id": "US",
"showAsSelected": true
}, {
"id": "BR",
"showAsSelected": true
}, {
"id": "AO",
"showAsSelected": true
}, {
"id": "KE",
"showAsSelected": true
}, {
"id": "NG",
"showAsSelected": true
}, {
"id": "ZA",
"showAsSelected": true
}, {
"id": "AE",
"showAsSelected": true
}, {
"id": "CN",
"showAsSelected": true
}, {
"id": "ID",
"showAsSelected": true
}, {
"id": "IN",
"showAsSelected": true
}, {
"id": "JP",
"showAsSelected": true
}, {
"id": "KR",
"showAsSelected": true
}, {
"id": "KW",
"showAsSelected": true
}, {
"id": "OM",
"showAsSelected": true
}, {
"id": "TW",
"showAsSelected": true
}, {
"id": "HK",
"showAsSelected": true
}, {
"id": "SG",
"showAsSelected": true
}, {
"id": "AU",
"showAsSelected": true
}]
},
areasSettings: {
autoZoom: true,
color: "#B4B4B7",
colorSolid: "#40E0D0",
selectedColor: "#40E0D0",
outlineColor: "transparent",
rollOverColor: "#666",
rollOverOutlineColor: "transparent"
}
});
$('#nav li:has(ul)').doubleTapToGo();
var show_menu = document.querySelector('.show_menu_btn');
show_menu.addEventListener('click', function(event) {
var target = document.querySelector(show_menu.getAttribute('data-target'));
if (target.style.display == "none") {
target.style.display = "block";
show_menu.innerHTML = show_menu.getAttribute('data-shown-text');
} else {
target.style.display = "none";
show_menu.innerHTML = show_menu.getAttribute('data-hidden-text');
}
});
如果你清晰地縮進代碼,請通過減少你的代碼到一個最小的例子的適當的措施,並在錯誤觀察信息消息,你會發現這個問題。 –
錯誤的解釋是,您在塊(compund語句)之後使用逗號運算符,這在語法上不正確。然而,你的實際問題是,你對使用大括號的時候似乎很困惑。 – Xufox