2014-04-28 107 views
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(); 
}); 
+1

'Engine'不'var'定义...... –

+0

@ PC-射手它将全球,如果你忽略它。我知道这很丑陋。 – A1rPun

回答

0

也许,这是由于这样绑定到该函数的范围在函数中使用Engine,只。尝试首先在全局声明引擎,例如在使用

var Engine; 

或附加在该函数中的onclick处理程序使用

$("button.your-button").click(Engine.search.globalSearch); 

第一行这也将涵盖了在方法中声明援引为从使用内联onclick处理与事件处理程序所产生的可能的冲突在DOMReady事件上晚了。