如何在另一个文件的HTML上加载js动作

how to load js action on html of another file

本文关键字:加载 js 动作 HTML 另一个 文件      更新时间:2023-09-26

我有两个不同文件的场景,我需要在另一个html中加载一个html。

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中保留select标签,它应该在iframe之外。

我们怎样才能使它可行?

你应该知道,iframe和父窗口之间的通信是如何工作的。下面的代码可以用来调用父窗口方法。

window.parent.functionName();