如何为 MenuList 中的动态 MenuItem 添加 CSS 以及如何在 XUL 中获取 MenuItem 的值

发布于 2024-11-29 04:42:46 字数 2856 浏览 1 评论 0 原文

我想创建如图所示的菜单列表。 在此处输入图像描述

https://developer.mozilla.org/En/XUL:menuitem#Examples 当我检查 Firefox 网站时,它显示 “注意:menitem 必须有一个 menuitem-iconic 类才能显示图像。”

在我的例子中,我从 XUL 树动态加载 menuItems(获取 XUL 树的值并将其附加到 MenuList 中)。

这是菜单列表:

<menulist id="firstname">
    <menupopup >    
    </menupopup>
    </menulist>

<menulist id="laastname">
    <menupopup>         
    </menupopup>
    </menulist> 

CSS 文件:

.menu-iconic-left {
  min-width: 1.45em;
}

.menu-iconic-icon {
  width: 16px;
  height: 16px;
}

menu.menu-iconic > .menu-iconic-left,
menuitem.menuitem-iconic > .menu-iconic-left {
  -moz-appearance: menuimage;
  padding-top: 2px;
}

我从 Firefox 浏览器的 chrome 目录中找到了所有这些 CSS 代码: “jar:file:///C:/Program%20Files/Mozilla%20Firefox/chrome/classic.jar!/skin/classic/global/menu.css”。

  1. 如何使用 CSS 创建标志性菜单列表?

我的第二个问题是获取菜单项的值。正如我上面所说,我能够获取树单元格文本并将其附加到菜单列表中的菜单项。 我有大约 8 个菜单列表,在用户决定选择值后,我想获取这些值并将其附加到我的 XML 文件中。

我正在尝试这种方式,但似乎这不是正确的方法,因为它从 MenuList 获取 MenuItem 的值。

function mer()
{
alert('one' ); //This aler is working.

var src = "\n\<CONTACT>\n\
\<FirstName>"+document.getElementById("firstname").value+"</FirstName>\n\   //the id of the menulist.
\<LastName>"+document.getElementById("laastname").value+"</LastName>\n\     //the id of the seconf menulist.
\</CONTACT>\n";

alert('one' );  //This alert is not working.

var node = srcToNode(src);
alert(node);
    if (objXMLDoc.childNodes && objXMLDoc.childNodes.length) {
        for (var i = 0; i < objXMLDoc.childNodes.length; ++i) {
    if (objXMLDoc.childNodes.item(i).childNodes && objXMLDoc.childNodes.item(i).childNodes.length) {
         var x = objXMLDoc.childNodes.item(i).childNodes.length;
        var lastNode = objXMLDoc.childNodes.item(i).childNodes.item(x-2); } } }
objXMLDoc.appendChild(node);
var textNode = document.createTextNode("\n");
objXMLDoc.appendChild(textNode);

var textNode1 = document.createTextNode("\n");
objXMLDoc.appendChild(textNode1);

var serializer = new XMLSerializer();
var prettyString = serializer.serializeToString(objXMLDoc);
prettyString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + prettyString;
//saveFile(prettyString, "C:\\merge.xml");
alert('Merge is done');
document.getElementById('group').setAttribute("hidden", "true");

} 

function srcToNode(src) {
    var domObject = (new DOMParser()).parseFromString(src, "text/xml");
    return domObject.documentElement;
} 

2.我如何获取menuList 的menuItems 的值并将其更新到我的XML 文件。

感谢您的帮助和支持。

I want to create menuList as displayed in the picture.
enter image description here

https://developer.mozilla.org/En/XUL:menuitem#Examples
When I checked in the Firefox website, it shows
"Note: The menuitem must have a class of menuitem-iconic for the image to appear. "

In my case I'm loading the menuItems dynamically from the XUL tree(Getting the value of the XUL tree and append it in the MenuList).

This is the menuList:

<menulist id="firstname">
    <menupopup >    
    </menupopup>
    </menulist>

<menulist id="laastname">
    <menupopup>         
    </menupopup>
    </menulist> 

The CSS file:

.menu-iconic-left {
  min-width: 1.45em;
}

.menu-iconic-icon {
  width: 16px;
  height: 16px;
}

menu.menu-iconic > .menu-iconic-left,
menuitem.menuitem-iconic > .menu-iconic-left {
  -moz-appearance: menuimage;
  padding-top: 2px;
}

I found all these CSS code from the chrome directory of my Firefox browser:
"jar:file:///C:/Program%20Files/Mozilla%20Firefox/chrome/classic.jar!/skin/classic/global/menu.css".

  1. How can i create a Iconic menulist using CSS?

My Second problem to get the value of the menuItem. As i said above, I'm able to get the tree cell text and append it to the MenuItem in the Menulist.
I have around 8 Menulist and after the user decides to choose the values, then I want to get those values and append it to my XML file.

I'm trying in this way, but it's seems like this is not the proper way of doing becasue it's getting the value of the MenuItem from the MenuList.

function mer()
{
alert('one' ); //This aler is working.

var src = "\n\<CONTACT>\n\
\<FirstName>"+document.getElementById("firstname").value+"</FirstName>\n\   //the id of the menulist.
\<LastName>"+document.getElementById("laastname").value+"</LastName>\n\     //the id of the seconf menulist.
\</CONTACT>\n";

alert('one' );  //This alert is not working.

var node = srcToNode(src);
alert(node);
    if (objXMLDoc.childNodes && objXMLDoc.childNodes.length) {
        for (var i = 0; i < objXMLDoc.childNodes.length; ++i) {
    if (objXMLDoc.childNodes.item(i).childNodes && objXMLDoc.childNodes.item(i).childNodes.length) {
         var x = objXMLDoc.childNodes.item(i).childNodes.length;
        var lastNode = objXMLDoc.childNodes.item(i).childNodes.item(x-2); } } }
objXMLDoc.appendChild(node);
var textNode = document.createTextNode("\n");
objXMLDoc.appendChild(textNode);

var textNode1 = document.createTextNode("\n");
objXMLDoc.appendChild(textNode1);

var serializer = new XMLSerializer();
var prettyString = serializer.serializeToString(objXMLDoc);
prettyString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + prettyString;
//saveFile(prettyString, "C:\\merge.xml");
alert('Merge is done');
document.getElementById('group').setAttribute("hidden", "true");

} 

function srcToNode(src) {
    var domObject = (new DOMParser()).parseFromString(src, "text/xml");
    return domObject.documentElement;
} 

2.How can i get the value of of my menuItems of menuList and update it to my XML file.

Thanks for your help and support.

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

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

发布评论

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

评论(1

蒲公英的约定 2024-12-06 04:42:46

首先,要创建带有图标的菜单项,只需将菜单项的类设置为包含“menuitem-iconic”即可。您可以通过在类中包含“menu-iconic”来在菜单上执行相同的操作。例如:

<menulist id="metasyntactic" class="menu-iconic">
  <menupopup>
    <menuitem class="menuitem-iconic" value="foo">Foo</menuitem>
    <menuitem class="menuitem-iconic" value="bar">Bar</menuitem>
    <menuitem class="menuitem-iconic" value="baz">Baz</menuitem>
  </menupopup>
</menulist>

您可能已经知道这一点,但是菜单列表提供了一种非常方便的方法,可以为您添加菜单项:(

document.getElementById("metasyntactic").appendItem("Zed", "zed");

请参阅https://developer.mozilla.org/en/XUL/menulist#m-menulist.appendItem)

其次,可以获取选中的menuitem的值通过简单地读取菜单列表的 value 属性:(

var selectedValue = document.getElementById("metasyntactic").value;

参见 https://developer.mozilla .org/en/XUL/menulist#a-value)

First, to create a menuitem with an icon, just set the class of the menuitem to include 'menuitem-iconic'. You can do the same on the menu by including 'menu-iconic' in the class. For example:

<menulist id="metasyntactic" class="menu-iconic">
  <menupopup>
    <menuitem class="menuitem-iconic" value="foo">Foo</menuitem>
    <menuitem class="menuitem-iconic" value="bar">Bar</menuitem>
    <menuitem class="menuitem-iconic" value="baz">Baz</menuitem>
  </menupopup>
</menulist>

You may already know this, but the menulist provides a very handy method that adds a menuitem for you:

document.getElementById("metasyntactic").appendItem("Zed", "zed");

(see https://developer.mozilla.org/en/XUL/menulist#m-menulist.appendItem)

Secondly, you can get the value of the selected menuitem by simply reading the value property of the menulist:

var selectedValue = document.getElementById("metasyntactic").value;

(see https://developer.mozilla.org/en/XUL/menulist#a-value)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文