如何将的整个区域设为在 XUL 中可点击?

发布于 2024-12-05 22:28:46 字数 846 浏览 0 评论 0原文

尝试学习一些 XUL,但有点卡住了。首先建立一个非常基本的专辑列表。

假设我有这个框 - 歌曲列表开始隐藏,但我想在单击主 albuminfo 框时显示它。

<box align="left" class="album"  id="test" orient="vertical">
    <box class="albumInfo" ><description value="Album 1" class="albumName"/><label class="albumArtist" value="Album artist 1"/></box>
    <box><label value="Year of release"/><label value="Genre"/></box>

    <listbox align="left" class="songlist" collapsed="true">
        <listitem label="Song 1"/>
        <listitem label="Song 2"/>
        <listitem label="Song 3"/>
        <listitem label="Song 3"/>
        <listitem label="Song 5"/>
    </listbox>
</box>

单击整个 albuminfo 框区域时如何触发 Javascript 命令?我可以很好地使用按钮,但我真的想让整个框区域都可单击。

Trying to learn a bit of XUL but am a bit stuck. Building a very basic album list to start.

So say I have this box - the song list starts hidden but I want to show it when I click on the main albuminfo box.

<box align="left" class="album"  id="test" orient="vertical">
    <box class="albumInfo" ><description value="Album 1" class="albumName"/><label class="albumArtist" value="Album artist 1"/></box>
    <box><label value="Year of release"/><label value="Genre"/></box>

    <listbox align="left" class="songlist" collapsed="true">
        <listitem label="Song 1"/>
        <listitem label="Song 2"/>
        <listitem label="Song 3"/>
        <listitem label="Song 3"/>
        <listitem label="Song 5"/>
    </listbox>
</box>

How can I fire a Javascript command when I click the entire albuminfo box area? I can use a button just fine, but I really want to make the entire box area clickable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暖阳 2024-12-12 22:28:46

您可以在 XUL 中通过多种方式完成此操作。既然您要求通过单击按钮来实现这一点,那么您就可以:

    <?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<box align="left" class="album"  id="test" orient="vertical">
    <box class="albumInfo" ><description value="Album 1" class="albumName"/>
<label class="albumArtist" value="Album artist 1"/>
</box>
    <box><label value="Year of release"/><label value="Genre"/></box>

    <listbox align="left" class="songlist" collapsed="true" id="listBox" >
        <listitem label="Song 1"/>
        <listitem label="Song 2"/>
        <listitem label="Song 3"/>
        <listitem label="Song 3"/>
        <listitem label="Song 5"/>
    </listbox>
</box>
<row><button label="Album Info" oncommand="Open();"/> </row>

<script type="application/x-javascript">
<![CDATA[
   function Open()
{
document.getElementById('listBox').setAttribute("collapsed", "false");

}

]]>
</script>

</window>

当您单击按钮时,您将获得专辑信息!

如果没有,您可以使用此选项,当您单击框上的任意位置时,列表框将打开,只需稍微更改上面的内容即可。

<box align="left" class="album"  id="test" orient="vertical" onclick="OpenInfo()">

function OpenInfo()
{
alert('hi');
document.getElementById('listBox').setAttribute("collapsed", "false");

}

您可以通过多种方式操作列表。如需更多参考,请查看此链接:https://developer.mozilla.org/en/XUL_Tutorial/Manipulated_Lists

you can do it many ways in XUL. SInce you asked a simple way doing it by clicking a button, here you go:

    <?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<box align="left" class="album"  id="test" orient="vertical">
    <box class="albumInfo" ><description value="Album 1" class="albumName"/>
<label class="albumArtist" value="Album artist 1"/>
</box>
    <box><label value="Year of release"/><label value="Genre"/></box>

    <listbox align="left" class="songlist" collapsed="true" id="listBox" >
        <listitem label="Song 1"/>
        <listitem label="Song 2"/>
        <listitem label="Song 3"/>
        <listitem label="Song 3"/>
        <listitem label="Song 5"/>
    </listbox>
</box>
<row><button label="Album Info" oncommand="Open();"/> </row>

<script type="application/x-javascript">
<![CDATA[
   function Open()
{
document.getElementById('listBox').setAttribute("collapsed", "false");

}

]]>
</script>

</window>

When you click the button you will get your Album Info!!!

If not, you can use this option, when you click anywhere on the box, you listbox will open, by changing above slightly.

<box align="left" class="album"  id="test" orient="vertical" onclick="OpenInfo()">

function OpenInfo()
{
alert('hi');
document.getElementById('listBox').setAttribute("collapsed", "false");

}

You can manipulate list in many ways. For more reference please check this link: https://developer.mozilla.org/en/XUL_Tutorial/Manipulating_Lists

○闲身 2024-12-12 22:28:46

用户可以通过多种方式触发XUL中的command事件。例如:用鼠标单击元素,当焦点位于元素上时按默认热键(SpaceEnter 按钮),单击元素的标签,按元素或元素标签的访问键。从您的问题的声音来看,您实际上只对元素本身上的鼠标单击感兴趣,并且不需要 command 事件提供的所有其他可访问性。这意味着您可以简单地监听 click 事件:

<box class="albumInfo" onclick="...">

例如,如果单击元素,您可以触发现有的 元素:

<box class="albumInfo" onclick="document.getElementById('album-info-command').doCommand();">

The user can trigger the command event in XUL by multiple means. For example: click the element with the mouse, press a default hotkey (Space or Enter for a button) when focus is on the element, click the element's label, press the element's or element label's access key. From the sound of your question, you are really only interested in mouse clicks on the element itself and you don't need all the additional accessibility provided by the command event. Which means that you can simply listen to the click event:

<box class="albumInfo" onclick="...">

You could for example trigger an existing <command> element if the element is clicked:

<box class="albumInfo" onclick="document.getElementById('album-info-command').doCommand();">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文