2015-07-21 21 views
0

Html中的Java腳本如下。加載Javascript/jQuery不能在HTML中工作

$(document).ready(function() { 
 
    var found = {{.found}} 
 
    window.alert("hiiii"); 
 
    if (foundRecords==true) { 
 
     document.getElementById("abc").style.display = "block"; 
 
    } 
 
    return  
 
});

這應該在HTML加載的時間得到加載。但它並沒有完全加載。在這個簡單的代碼和平中,我沒有發現任何錯誤。

+1

什麼是'{{;實測值}}'?你在'console'中遇到錯誤嗎? – Tushar

+1

另外,'foundRecords'不能爲真,因爲它沒有被定義。 –

+0

在控制檯中沒有錯誤 –

回答

1

,如果你想獲得與階級分子發現{{;實測值}}

window.onload = function() 
{ 
    var found = document.getElementsByClassName("found"); 
    if (found) { 
     document.getElementById("abc").style.display = "block"; 
    } 

} 
+0

nope,發現不是一種風格或類..它是一個布爾變量,我從beego cotroller ....和更多的控制本身不是去這個函數 –

+0

所以你必須定義和初始化var foundRecords,在你的代碼foundRecords是未定義的變量@VijayKumar –

+0

是的,我已經初始化......但我說,即使警報,即使外部條件也沒有執行,意味着控制不在document.ready中 –

0

如果你使用jQuery加載功能將採取略有變化:

$(document).ready(function() { 
    // get the class found and assign it to a variable found 
    var found = $('.found') // it was {{.found}} producing an error 
    window.alert("hiiii"); 
    // where does foundRecords come from? it is up to you to clear this 
    if (foundRecords == true) { 
     document.getElementById("abc").style.display = "block"; 
    } 
    // what is the return good for? 
    // it would be better to return true or false 
    // or leave it away 
    return; 
}); 

檢查的jsfiddle:

http://jsfiddle.net/bx0e18L4/

現在警報消息,但仍與變量foundRecords有問題。保重。

編輯:

根據您的意見變量foundRecords上面應該是found,使臨界線應該是:

if (found == true) { // processing }