2016-12-07 34 views
1

我不擅長腳本,我無法弄清楚我的執行出了什麼問題。無法獲得Javascript文件在頁面上運行

該網頁是http://snmcsupport.com/map-js-test-page,它應該運行一個腳本來產生一個可點擊的地圖。腳本本身是非常長的,所以我不會在這裏貼,但你可以看到它if you click here

在我的網頁,我要運行腳本在頭

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> 
</script> 

<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.4/raphael-min.js"> 
</script> 

<script src="//cdnjs.cloudflare.com/ajax/libs/qtip2/2.1.1/jquery.qtip.min.js"> 
</script> 

在必要的標記我網頁,我叫腳本

<div> 
    <script type="text/javascript" src="http://snmcsupport.com/wp-includes/js/app.js"> 
    </script> 
</div> 

但我仍然無法獲得代碼運行?從開發商也初步說明說:

The last step is to initialize the map by making the following script calls:

<script>makeaClickableMap.initialize(<your-document-object-model-handle>);</script> 

where your-object-document-model handle can be anything actually:

a jQuery object like $("#map")

a Javascript Document Object Model like document.getElementById("map")

or a simple string like "map"

,但我想不出是什麼意思。如果我嘗試在網頁中輸入初始化命令,我會遇到一個令人討厭的交叉腳本錯誤,它不會讓我知道。

我在使用Divi兒童主題的Wordpress上運行此操作。

+0

如何使用WordPress jQuery文件和嵌入qtip和拉斐爾在兒童主題?你用wp_enqueue_script('jquery')正確排列你的js嗎? ... – Benoti

+0

可能不是......該腳本的開發人員不直接與WP或Divi工作;我認爲他是在假定它直接嵌入到HTML中的情況下編寫的。我需要做整個字符串:wp_enqueue_script(string $ handle,string $ src ='',array $ deps = array(),string | bool | null $ ver = false,bool $ in_footer = false) –

回答

0
makeaClickableMap.initialize(<your-document-object-model-handle>); 
      //this is the element that will --^ 
      //be used to contain your rendered map

​​期望用戶通過它在要在地圖顯示一個HTML元素的參考的方法。元素可以通過

  • 他們的標籤名(DIV,P,H1等)

  • 類名稱<div class="className></div>

  • 或辨識的名字,我會在這裏展示標識:

首先,你; 11需要與它相關聯的ID的元素,它應放在<body>標記內:

<div id="map"></div>

這個標籤之下,但仍然在body標籤中,你需要包括makeClickableMap.initialise呼叫,並通過在這個<div>的ID:

<!-- Javascript solution: --> 
<script> 
    makeaClickableMap.initialize(document.getElementById('map')); 
</script> 
<!-- notice that the id is just 'map' here -->

到Javscript替代上面的解決方案是使用jQuery如下(你仍然需要帶ID的div):

<!-- jQuery solution: --> 
<script> 
    makeaClickableMap.initialize($('#map')); 
</script> 
<!-- notice the ID is prefixced with a '#' character-->
+0

那麼是什麼? ...... –

+0

如果我這樣做,我會得到「WatchGuard防火牆拒絕的請求。 原因:IPS爲「WEB跨站點腳本-32/Web攻擊」 請與管理員聯繫以尋求幫助檢測」 –

+0

發佈的jsfiddle,如果你能 – Pineda

相關問題