2016-09-29 118 views
-1

我有兩個不同文件的場景,我需要在另一個文件中加載一個html。如何在另一個文件的html上加載js動作

Iframe.html的:

<select data-placeholder="Choose a Country..." class="flexselect"> 
    <option value=""></option> 
    <option value="United States">United States</option> 
    <option value="United Kingdom">United Kingdom</option> 
    <option value="Afghanistan">Afghanistan</option> 
    <option value="Algeria">Algeria</option> 
    <option value="Bermuda">Bermuda</option> 
    <option value="Bhutan">Bhutan</option> 
</select> 
<iframe src="index.html" style="width:100%; border: 0px solid #fff;"></iframe> 

的index.html:

<!doctype html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <link rel="stylesheet" href="http://rmm5t.github.io/jquery-flexselect/flexselect.css"> 
    </head> 
    <body> 
     <script src="http://code.jquery.com/jquery-1.6.4.js" type="text/javascript"></script> 
     <script src="http://rmm5t.github.io/jquery-flexselect/jquery.flexselect.js" type="text/javascript"></script> 
     <script src="http://rmm5t.github.io/jquery-flexselect/liquidmetal.js" type="text/javascript"></script> 
     <script type="text/javascript"> 
      $(document).ready(function(){ 
       $("select.flexselect").flexselect(); 
      }); 
    </script>   
    </body> 
</html> 

它不會顯示在其沒有工作過,同時任何錯誤。我所觀察到的是,它不在iframe標籤上方的select標籤上觸發。

如果我將選擇標記內容保留在index.html頁面中,但iframe不允許顯示完整的下拉內容,則可以使用。它被限制在允許滾動的特定高度&。

所以我不能保持在iframe選擇標記,它應該走出iframe的。

我們該如何使它可行?

+0

即使您將select添加到index.html,您也會困惑嗎? – snit80

+0

@ snit80,是的..iframe必須在我的情況。情況就像我需要在另一個文件中加載index.html文件,所以我使用iframe。但是,當我在iframe中保留select標籤時,這是問題(http://stackoverflow.com/questions/39741412/jquery-chosen-content-not-getting-out-of-the-if​​rame-instead-scrolled-within- ) – kumar

+0

你有沒有考慮給iframe一個高度? – snit80

回答

1

你應該知道,如何iframe和父窗口的作品之間的通信。 下面的代碼可以用來調用父窗口方法。

window.parent.functionName(); 
+0

你想讓我保留這個window.parent.functionName(); – kumar

+0

在iframe.html中創建函數,並從index.html調用相同的函數 –

+0

這工作(本地測試)..但不是在我的情況下..我不能在iframe.html中寫入js代碼:(它不會加載javascript,這又是一個不同的故事:'( – kumar

相關問題