跳轉到內容

XForms/複選框

來自華夏公益教科書,自由的教科書

您有一個布林真/假值,並且希望輸入控制元件對是/否或真/假答案有一個簡單的複選框。

我們將使用標準輸入控制元件,但使用 bind 語句將例項繫結到布林資料型別。我們將透過兩種方式執行此操作,一種是使用沒有 ID 的 bind,另一種是使用帶有 ID 的 bind,以便我們可以引用 bind 語句。

請注意,複選框也可以透過使用xf:select控制元件來演示。但在這種情況下,一系列用空格分隔的值儲存在與控制元件關聯的值中。

螢幕影像

[編輯 | 編輯原始碼]
使用輸入控制元件的布林複選框
[編輯 | 編輯原始碼]

載入 XForms 應用程式

示例程式

[編輯 | 編輯原始碼]
<html
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:xf="http://www.w3.org/2002/xforms"
   xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <head>
      <title>XForms Checkbox Demo</title>
      <style type="text/css"><![CDATA[body {font-family: Helvetica, sans-serif;}]]>
      </style>
      <xf:model>
         <!-- load the module test data into the model -->
         <xf:instance xmlns="">
            <data>
               <bool1>true</bool1>
               <bool2>false</bool2>
            </data>
         </xf:instance>
         <!-- Here is where we indicate the datatypes of the instance variables -->
         <xf:bind ref="bool1" type="xs:boolean"  />
         <xf:bind id="bool2" ref="bool2" type="xs:boolean"  />
      </xf:model>
   </head>
   <body>
      <h1>XForms Checkbox Demo</h1>
      <xf:input ref="bool1">
         <xf:label>Bool 1: </xf:label>
      </xf:input>
      <br />
      <!-- use a named binding -->
      <xf:input bind="bool2">
         <xf:label>Bool 2: </xf:label>
      </xf:input>
      <br />
      <xf:output ref="bool1">
         <xf:label>Bool 1: </xf:label>
      </xf:output>
      <br />
      <xf:output bind="bool2">
         <xf:label>Bool 2: </xf:label>
      </xf:output>
   </body>
</html>
下一頁: Select1 | 上一頁: 帶樣式的文字區域
首頁: XForms
華夏公益教科書