简体   繁体   English

如何从另一个 HTML 页面获取元素

[英]How to get element from another HTML page

I'm very new to tizen web.我对 tizen web 很陌生。 I have an app that gets data from mqtt broker and controls wi-fi lamp.我有一个从 mqtt 代理获取数据并控制 wi-fi 灯的应用程序。 I have list page with 3 pages, that allow to control brightness, speed, scale.我有 3 页的列表页,可以控制亮度、速度、比例。 I get data from mqtt every time when the lamp changes its state and I want to update the level in each page.每次当灯改变其 state 时,我都会从 mqtt 获取数据,并且我想更新每个页面中的级别。

index.html索引.html

<div class="ui-content">
    <ul class="ui-listview">
        <li class="li-has-toggle">
            <label>
                On/Off
                <div class="ui-toggleswitch" id="toggle">
                    <input class="ui-switch-input" id="t_swtch" type="checkbox" onclick="ToggleSwitch();" />
                    <div class="ui-switch-button"></div>
                </div>
            </label>
        </li>
        <li>
            <a href="brightness.html">Brightness</a>
        </li>
        <li>
            <a href="speed.html">Speed</a>
        </li>
        <li>
            <a href="scale.html">Scalse</a>
        </li>
    </ul>
</div>

brightness.html亮度。html

<body>
    <div class="ui-page" id="dimmer-page">
        <div class="ui-content dimmer-content">
            <div class="ui-dimmer" id="dimmer" data-dimmer-type="BRI"></div>
            <input id="slider" data-slider-type="bri" type="range" value="50" min="0" max="100">
        </div>
    </div>
</body>

I tried to get element from brightness.html like this document.querySelector("input[data-slider-type='bri']") to set value, but it returns null .我试图从亮度.html 像这个document.querySelector("input[data-slider-type='bri']")中获取元素来设置值,但它返回null When I try to get access to this element of index.html document.getElementById("t_swtch") and it works fine.当我尝试访问index.html document.getElementById("t_swtch")的这个元素时,它工作正常。 I need to get access to this element from my index.html page.我需要从我的index.html页面访问这个元素。

Not sure it's the case, but maybe there's a typo in your query.不确定是不是这样,但您的查询中可能有错字。 I've tried the exact same query you use, but with the closing ) - document.querySelector("input[data-slider-type='bri']") and it returned the corresponding element我已经尝试过您使用的完全相同的查询,但使用结束) - document.querySelector("input[data-slider-type='bri']")它返回了相应的元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM