2009年1月30日

window:操控器六頁

window | 特徵一頁 | 二頁 | 三頁 | 四頁 | 五頁
方法一頁 | 二頁 | 三頁 | 四頁 | 五頁 | 六頁 | 七頁
操控器一頁 | 二頁 | 三頁 | 四頁 | 五頁 | 六頁 | 七頁 | 成員表
window 的事件操控器
onreset

當用戶點選重設(<input type='reset'>)時,會啟動此事件操控器。在 Firefox, Safari, Chrome 可以用 window.onreset;在 IE 必須使用於 FORM 元素。

  • 程式用法:

    <script type='text/javascript'>
    function onresetHd(e)
    {
      var e = e || window.event;
      onresetSet(null);
      alert('重設 '+ e);
    }
    function onresetSet(hd)
    {
      if( window.outerWidth == undefined )
        document.getElementById('fm').onreset=hd;
      else
        window.onreset=hd;
    }
    </script>
    <a href='javascript:onresetSet(onresetHd)'>設定操控器</a>
    <form id='fm'>
    <input type="reset" value="重設" />
    </form>

  • 執行結果:

    設定操控器

onselect

INPUTTEXTAREA 中用滑鼠選文字,會啟動此事件操控器。在 Firefox, Safari, Chrome 可以用 window.onselect;在 IE 必須使用於輸入元素。

  • 程式用法:

    <script type='text/javascript'>
    function onselectHd(e)
    {
      var e = e || window.event;
      onselectSet(null);
      alert('選文字 '+ e);
    }
    function onselectSet(hd)
    {
      if( window.outerWidth == undefined )
        document.getElementById('seltext').onselect=hd;
      else
        window.onselect=hd;
    }
    </script>
    <a href='javascript:onselectSet(onselectHd)'>設定操控器</a> //
    <input id='seltext' size='24' value='選此文字' />

  • 執行結果:

    設定操控器 //

onsubmit

當用戶點選送出(<input type='submit'>)時,會啟動此事件操控器。在 Firefox, Safari, Chrome 可以用 window.onsubmit;在 IE 必須使用於 FORM 元素。操控器函式回傳 false 可以停止系統預設的操控器。

  • 程式用法:

    <script type='text/javascript'>
    function onsubmitHd(e)
    {
      var e = e || window.event;
      onsubmitSet(null);
      alert('送出 '+ e);
      return false;
    }
    function onsubmitSet(hd)
    {
      if( window.outerWidth == undefined )
        document.getElementById('sufm').onsubmit=hd;
      else
        window.onsubmit=hd;
    }
    </script>
    <a href='javascript:onsubmitSet(onsubmitHd)'>設定操控器</a>
    <form id='sufm'>
    <input type="submit" value="送出" />
    </form>

  • 執行結果:

    設定操控器


©2008-2009 by ant2legs, All Rights Reserved. ant2legs 擁有其製作的文章,圖片與程式的著作權,所有權利保留。