javascript
  • jquery
  • datatables
  • 2016-01-13 28 views 0 likes 
    0

    投影圖像這是我的邏輯樹:加入設在我與jQuery

    enter image description here

    consultaBeneficiario.js下面

    這是數據表插件的回調:

    "fnDrawCallback": function() { 
    
         $("tbody td.xls").each(function(){    
          $(this).html("<img src='../plusDetails.png' onclick = 'dettaglioConsultaPagamentiXLS("+$(this).html()+", \"beneficiario\")\'> XLS </button>"); 
         }); 
    

    但它不起作用。

    這是結果:

    enter image description here

    如果我這樣做,例如:

    $(this).html("<img src='http://i.imgur.com/SD7Dz.png' onclick = 'dettaglioConsultaPagamentiXLS("+$(this).html()+", \"beneficiario\")\'> XLS </button>"); 
    

    作品。

    我使用百里香,如果它可以幫助。

    爲什麼?

    +0

    你用你的圖片的靜態鏈接試試嗎? –

    +2

    相對圖像路徑基於HTML頁面位置,而不是腳本文件所在的位置。 –

    +0

    開始標記是'img',但結束標記是'按鈕'! – oneNiceFriend

    回答

    1

    因爲'../'是從您的主html/php文檔解釋而不是從您的腳本的位置。設置完整的URL(你可以將其定義/或抓住它作爲一個jQuery變量)

    +0

    這是一個Spring項目..剛纔,我在想如果可能使用'../',它是? – Dave

    0

    嘗試使用像

    var BASEURL = window.location.protocol+'//'+window.location.hostname+((window.location.port=='') ? '' : ':'+window.location.port)+'/'; 
    

    一個的BaseURL變量之後,你可以用它來設置一個靜態鏈接的圖像

    $(this).html("<img src='"+BASEURL+"pagamenti/plusDetails.png' onclick = 'dettaglioConsultaPagamentiXLS("+$(this).html()+", \"beneficiario\")\'></img>"); 
    
    相關問題