如何从另一个编辑html文件

时间:2017-10-08 19:42:31

标签: javascript jquery html electron

我想从另一个html文档sidebar中选择downloader.htmlsettings.html id的元素。

downloader.html

    <body>
<div class="ui visible left vertical thin sidebar menu" id='sidebar'>
    <div class='item'>
        <img class='ui medium image' src='./../../resources/images/logo_256x256.png'>
    </div>
    <a class="item" id='dashboard_btn'>
        <i class="desktop icon"></i>
        Dashboard
      </a>
    <a class="item" id='statistics_btn'>
        <i class="area chart icon"></i>
        Statistics
      </a>
    <a class="item" id='settings_btn'>
        <i class="settings icon"></i>
        Settings
      </a>
</div>
<div class='dimmed pusher'>
    <button class="ui icon button" id='sidebar_btn'>
        <i class="angle double left icon" id='sidebar_btn_icon'></i>
    </button>
    <div id='content'>
        <!-- All content goes here. -->
    </div>
</div>
<script>
    $(document).ready(function () {
        $('#sidebar_btn').on('click', function () {
            $('#sidebar').sidebar('toggle');

            $('#sidebar_btn_icon').toggleClass('right');
        });

        $("#dashboard_btn").on("click", function () {
            $("#content").load("./items/dashboard/dashboard.html");
        });
        $("#statistics_btn").on("click", function () {
            $("#content").load("./items/statistics/statistics.html");
        });
        $("#settings_btn").on("click", function () {
            $("#content").load("./items/settings/settings.html");
        });
    });
</script>

settings.html

<body>
<div class='center'>
    <h2 class="ui icon header">
        <i class="settings icon"></i>
        <div class="content">
            Settings
            <div class="sub header">Sample text.</div>
        </div>
    </h2>
    <div class='center child'>
        <div class="ui toggle checkbox">
            <input name="public" type="checkbox">
            <label>Dark theme.</label>
        </div>
    </div>

</div>
<script>
    //Select 'sidebar' element from downloader.html using jquery
</script>

请不要在html代码中注意混合'"。这是我的错,它将在应用发布之前修复。

1 个答案:

答案 0 :(得分:1)

您可以在“settings.html”

中使用哈希设置.load()
$("#element").load("downloader.html #sidebar")