2013-06-06 62 views
0

I have seen other javascript toggle questions on SO我在哪裏添加JavaScript中的可見性切換?

但是我有問題加入我的方法。我無法將頭放在需要放入的位置以使其工作。

這裏是有問題的JavaScript函數:

function injectProductIFrame(w,h){ 
     var job_id = $("#job_id").val(); 
     if(job_id != "0") 
     { 
      var url = "/technician/"+ job_id+"/addProducts"; 
      $("#iframeContainer").html('<iframe src="'+url+'" width='+w+' height='+h+' />'); 
     }else{ 
      alert("Please Select a Job First. Then you can add a product"); 
     } 
    } 

這裏是視圖部分:

</a><a href="#productaddAdd" role="" class="" data-toggle="modal"> 
           <button class="btn btn-large" id="product_frame" type="button" onClick='Javascript: injectProductIFrame("90%", "500")'> Product </button> 

沒有錯,但我希望的按鈕來關閉的iFrame如果iFrame顯示的東西。現在按鈕只是作爲「開」,再次點擊不會改變任何內容。

任何幫助將不勝感激。

+1

您可以創建一個的jsfiddle?想檢查你的html。 – yeyene

+0

我不善於使用該網站(又名我從未使用過) – notaceo

+0

或者您只是在您的問題中發佈您的HTML代碼。 – yeyene

回答

2

我想這一點,或者類似的東西,將工作

function injectProductIFrame(w,h){ 
    if($("#iframeContainer").html().length > 0) 
    { 
     $("#iframeContainer").hide();   
    } 
    else 
    { 
     $("#iframeContainer").show(); 

     var job_id = $("#job_id").val(); 
     if(job_id != "0") 
     { 
      var url = "/technician/"+ job_id+"/addProducts"; 
      $("#iframeContainer").html('<iframe src="'+url+'" width='+w+' height='+h+' />'); 
     }else{ 
      alert("Please Select a Job First. Then you can add a product"); 
     } 
    } 
} 
+0

這確實與一些調整工作,使開關切換 - 謝謝! – notaceo