2012-11-03 34 views
0

我想在搜索結果的網頁上顯示一條消息。下面是我的JS代碼。我保持DIV在HTML中爲空。在調用該函數後,瀏覽器中沒有顯示任何內容。我是新手請糾正我在做錯的地方。使用jquery輸出HTML內容

function test() { 
    var v = "<p class=""noresults""> <img src=""icons/oops-icon_small.jpg"" alt=""OOPS!"" > id=""img_align"" /> we did not find" + "any results relating to your search. </p>" + "<span > class=""noreult_home""> <a href=""#""><img src=""icons/home_icon.jpg"" alt=""Home""/>  </a> ></span>"; 

    $("div#con").html(v); 
} 
+2

你的HTML是可怕無效。垃圾進垃圾出。 – Quentin

+0

昆汀,感謝您在發帖後格式化我的問題我試圖糾正格式,因爲你是專家,你糾正它非常快。 – Balu

回答

2

我必須提高你的javscript功能

function test() { 
    var v= "<p class='noresults'><img src='icons/oops-icon_small.jpg' alt='OOPS!' id='img_align'/>we did not find any results relating to your search.</p><span class='noreult_home'><a href='#'><img src='icons/home_icon.jpg' alt='Home'/></a></span>"; 
    $("div#con").html(v); 
} 
+0

湯姆,謝謝你的迴應,它的工作:) – Balu

0

試試這樣說:

function test() { 
    $('<img />').attr('id', 'img_align').append('div#con'); 
    $('<p></p>').addClass('noresult_home').html('we did not find any results relating to your search.').append('div#con'); 
}