سؤال

هذا المثال من صفحة موزيلا هذه.

main.xul

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="main.css" type="text/css"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

    <box id="num" class="labeledbutton" title="Number of Things:" value="52"/>

    <button label="Show" oncommand="document.getElementById('num').showTitle(true)"/>
    <button label="Hide" oncommand="document.getElementById('num').showTitle(false)"/>
</window>

Main.CSS

box.okcancelbuttons {
    -moz-binding: url('main.xml#labeledbutton');
}

main.xml

<?xml version="1.0"?>
<binding id="labeledbutton">
  <content>
    <xul:label xbl:inherits="value=title"/>
    <xul:label xbl:inherits="value"/>
  </content>
  <implementation>
    <method name="showTitle">
      <parameter name="state"/>
      <body>
        if (state) document.getAnonymousNodes(this)[0].
          setAttribute("style","visibility: visible");
        else document.getAnonymousNodes(this)[0].
          setAttribute("style","visibility: collapse");
      </body>
    </method>
  </implementation>
</binding>

لماذا لا يعرض المربع عند النقر فوق الزر؟

هل كانت مفيدة؟

المحلول

وهناك عدد قليل من المشاكل :

بادئ ذي بدء ، في main.css تحدد الفصل الدراسي okcancelbuttons ولكن في Main.xul تشير إلى أ labeledbutton صف دراسي. يمكن أن يطلق على الفصل نفس الربط.

ثانياً main.xml ليست فقط XML صالحة (أبسط طريقة للتحقق من صحة هي تحميله في Firefox وسيبصق الأخطاء). يحتاج xmlns سمات لكل مساحات الأسماء التي تستخدمها. في هذه الحالة مساحة الاسم "الرئيسية" ، XBL و Xul. يجب تعريفها في المفقودين <bindings> عنصر حول <binding> عنصر.

سينتهي الأمر مثل هذا:

main.xml

<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 <binding id="labeledbutton">
  <content>
    <xul:label xbl:inherits="value=title"/>
    <xul:label xbl:inherits="value"/>
  </content>
  <implementation>
    <method name="showTitle">
      <parameter name="state"/>
      <body>
        if (state) document.getAnonymousNodes(this)[0].
          setAttribute("style","visibility: visible");
        else document.getAnonymousNodes(this)[0].
          setAttribute("style","visibility: collapse");
      </body>
    </method>
  </implementation>
 </binding>
</bindings>

نصائح أخرى

فقط جربها

Xul (Main.xul)

<box id="num" class="labeledbutton" title="Number of Things:" value="52"/>

<button label="Show" oncommand="document.getElementById('num').showTitle(true)"/>
<button label="Hide" oncommand="document.getElementById('num').showTitle(false)"/>

CSS (Main.CSS)

box.okcancelbuttons {
    -moz-binding: url('main.xbl#labeledbutton');
}

XBL (main.xbl)

<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl"
          xmlns:xbl="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 <binding id="labeledbutton">
  <content>
    <xul:label xbl:inherits="value=title"/>
    <xul:label xbl:inherits="value"/>
  </content>
  <implementation>
    <method name="showTitle">
      <parameter name="state"/>
      <body>
        if (state) document.getAnonymousNodes(this)[0].
          setAttribute("style","visibility: visible");
        else document.getAnonymousNodes(this)[0].
          setAttribute("style","visibility: collapse");
      </body>
    </method>
  </implementation>
 </binding>
</bindings>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top