跳轉至內容

XML - 管理資料交換/XUL/答案

來自華夏公益教科書,為開放世界提供開放書籍

練習

  1. 建立一個視窗,其中包含兩個文字框,它們位於視窗下方約 200 畫素處。使用垂直或水平佈局。標記每個文字框併為每個文字框設定預設值,這些預設值彼此不同。建立一個標有“交換文字”的按鈕。接下來,建立一個函式,當單擊該按鈕時,將交換來自一個文字框的文字到另一個文字框。
  2. 在此練習中,您需要建立兩個單獨的檔案。在一個頁面上,建立一個視窗,該視窗具有兩個帶標籤的面板,每個面板上都有不同的內容。在另一個頁面上,只需建立一個彈出選單,其中包含一個選單項“開啟”。建立一個函式,當單擊“開啟”選單選項時,將瀏覽器重定向到帶標籤的頁面。

問題 1:答案

XulNum1.js

	  function swap()
	  {
	    var noDanaObj=document.getElementById('nodana');
	    var onlyXulObj=document.getElementById('onlyxul');
	    var noDanaStr=noDanaObj.getAttribute("value");
	    var onlyXulStr=onlyXulObj.getAttribute("value");
	    noDanaObj.setAttribute("value",onlyXulStr);
	    onlyXulObj.setAttribute("value",noDanaStr); 

	  }

XulNum1.xul

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
   
   <window
       id="Ex1"
       title="Excercise 1"
       orient="vertical"
       xmlns= "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">    
   <script src="XulNum1.js" />

   
  <hbox width="200px" height="200px" flex = "1">
     <text value= "There is no Dana..." id="nodana" style="font-size:18pt"/>
  </hbox>

  <hbox width="200px" height="200px" flex = "1">
     <text value="There is only XUL" id="onlyxul" style="font-size:24pt"/>
  </hbox>

<box width="200px">
	<button id="swap" label="swap" default="true" oncommand="swap();"/>
</box>


</window>
華夏公益教科書