2016-08-22 150 views
0

我正在測試此代碼,它在此處工作http://www.w3schools.com/js/tryit.asp?filename=tryjs_debugger,但不在我的Joomla頁面上。該瀏覽器的控制檯錯誤是在文章底部代碼適用於W3shool測試頁面,但不適用於Joomla

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
<script type="text/javascript"> 
function toggleDiv(divId) { 
    $("#"+divId).toggle(); 
} 
</script> 

<a href="javascript:toggleDiv('myContent');" style="background-color: #ccc; padding: 5px 10px;">Toggle Button</a> 
<div id="myContent" style="background-color: #aaa; padding: 5px 10px;"> 
    The content in this div will hide and show (toggle) when the toggle is pressed. 
</div> 

63 tet.html:168遺漏的類型錯誤:無法讀取nulltoggleDiv的特性「切換」 @ 63 tet.html:168(匿名函數)@ VM4704 :1

我已經cheched源頁面和我的代碼是由服務器原封不動送回給我:

<div itemprop="articleBody"> 
 
\t \t <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
 
<script type="text/javascript"> 
 
function toggleDiv(divId) { 
 
    $("#"+divId).toggle(); 
 
} 
 
</script> 
 

 
<a href="javascript:toggleDiv('myContent');" style="background-color: #ccc; padding: 5px 10px;">Toggle Button</a> 
 
<div id="myContent" style="background-color: #aaa; padding: 5px 10px;"> 
 
    The content in this div will hide and show (toggle) when the toggle is pressed. 
 
</div> \t </div>

回答

0

這聽起來像Joomla過濾/黑名單某些關鍵字。您可以看到它試圖調用該函數:

nulltoggleDiv並訪問該屬性。

如果您按f12並搜索「toggleDiv」,您應該能夠在變形後看到實際的html。

簽出此文檔:

https://docs.joomla.org/Help16:Content_Article_Manager#Filtering_Options_.28HTML.29

從DOC:

Black List Filters 
The default filter method in Joomla! is 'Black List'. The default 'Black List' contains the following tags to exclude: 

'applet', 'body', 'bgsound', 'base', 'basefont', 'embed', 'frame', 'frameset', 'head', 'html', 'id', 'iframe', 'ilayer', 'layer', 'link', 'meta', 'name', 'object', 'script', 'style', 'title', 'xml' 
The default 'Black List' contains the following attributes to exclude: 

'action', 'background', 'codebase', 'dynsrc', 'lowsrc' 
You can 'Black List' (disallow) additional tags and attributes by adding to the Filter tags and Filter attributes fields, separating each tag or attribute name with a space or comma. If you select a Filter Type of "Black List", this list will always be used, plus any additional tags and attributes you add. 
+0

它似乎並不是,該頁面的源代碼顯示,我的代碼是存在的,見上面。有趣的是,如果你按上面的「運行」,你可以看到一個錯誤,但我無法理解它(我在這些初學者水平) – MiniMe

+0

當我按運行並單擊切換按鈕時,代碼工作正常。它隱藏並揭示了預期的div。 – RIanGillis

+0

有些時候,當我刷新頁面時,我得到了這個https://i.imgur.com/bi1dqTe.png,這與我的錯誤 – MiniMe

0

的問題似乎是與此參考

$("#"+divId).toggle(); 

後,我更換了以上

var element = document.getElementById(divId); 
    element.toggle(); 

的代碼工作

相關問題