0
我在我的js文件中的函数看起来像(见下文) - 我试着去调用一个按钮的功能,但它在IE8不会工作(得到一个“引擎是未定义”)在FF,铬它工作正常: HTML:通话功能
<button onclick="javascript:Engine.search.globalSearch(window.event);" type="button" class="btn btn-default">Søg</button>
JS:
jQuery(function ($) {
var $w = $(window),
$body = $('body'),
resizeTimer,
tablePx = 768,
desktopPx = 992,
winWidth = $w.width();
Engine = {
search: {
setupSearch: function() {
// Add eventlistener for search-submit on Enter keydown
$("#q").keydown(function (event) {
if (event.which === 13) {
return Engine.search.submitSearch();
}
});
// Datepicker settings
// adding datepicker to date fields from the ASK local Search resume
// Setting op opensourse Bootstrap datepicker
$('input.addDatePicker').datepicker({
format: 'dd.mm.yy'
});
},
globalSearch: function (event) {
if (event.type === 'click' || event.keyCode === 13 || event.which === 13) {
// (IE-fix) Prevent default form-submit on Enter-press
event.preventDefault();
event.cancelBubble = true;
// Get search-field and placeholder-tekst
var searchFld = document.getElementById("globalsearch");
var ph = searchFld.getAttribute("placeholder");
if (searchFld.value !== "" && searchFld.value !== ph) {
// Get sites-searchpage url, combine it with the searchword and open that url.
var searchUrl = searchFld.getAttribute("data-searchUrl");
var tmpUrl = searchUrl + "?q=" + searchFld.value;
window.location = tmpUrl;
}
else {
return false;
}
}
},
autoSumitSearch: function() {
// Submit search if autoSubmit is setup to true by editor (requires variable defined on SC page)
if (autoSubmit === true) {
Engine.search.submitSearch();
}
},
submitSearch: function() {
// Create outer form with search criteria, to be able to submit it outside Sitecores global form-element
var $ = jQuery;
var winLoc = String(window.location.href).replace(/[?&]page[=][^&#]?/, "");
var form = '<form style="display: none;" method="get" action="' + window.location.href + '">' +
'<input name="q" value="' + $("#q").val() + '">' +
//'<input name="page" value="' + $("#page").val() + '">' +
'<input name="ps" value="' + $("#ps").val() + '">' +
(($("#categ").length > 0) ? '<input name="categ" value="' + $("#categ").val() + '">' : '') +
(($("#c").length > 0) ? '<input name="c" value="' + $("#c").val() + '">' : '') +
(($("#ddlCategories").length > 0) ? '<input name="cat" value="' + $("#ddlCategories").val() + '">' : '') +
(($("#ddlSiteSections").length > 0) ? '<input name="ss" value="' + $("#ddlSiteSections").val() + '">' : '') +
(($("#df").length > 0) ? '<input name="df" value="' + $("#df").val() + '">' : '') +
(($("#dt").length > 0) ? '<input name="dt" value="' + $("#dt").val() + '">' : '') +
'</form>';
var $form = $(form).appendTo("body");
setTimeout(function() { $form.submit().remove(); }, 0);
return false;
}
},
};
// Initialize main script-Engine;
Engine.init();
});
'Engine'不'var'定义...... –
@ PC-射手它将全球,如果你忽略它。我知道这很丑陋。 – A1rPun