最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript初級(jí)教程(第五課)第2/4頁(yè)

 更新時(shí)間:2007年04月05日 00:00:00   作者:  

    文字域可以鏈接onBlur、onFocus和onChange事件。當(dāng)有人點(diǎn)擊文字域的里邊時(shí)則發(fā)生onFocus事件。而如果點(diǎn)擊文字域的外面或按了tab鍵時(shí)則發(fā)生onblur事件。如果有人改變了文字域內(nèi)的內(nèi)容然后轉(zhuǎn)到文字域外部的區(qū)域時(shí)則發(fā)生onChange事件。

    試著做這些事情看下面的文字域會(huì)發(fā)生什么情況。

   

   

    以下是編制方法:文字域的編碼:

    <input type="text" name="first_text" onFocus="writeIt('focus');" onBlur="writeIt('blur');" onChange="writeIt('change');">

    每一個(gè)事件處理器調(diào)用函數(shù)writeIt(),該函數(shù)已作了定義。編碼如下:

    <script language="JavaScript">
    <!-- hide me
        function writeIt(the_word)
        {
            var word_with_return = the_word + "\n";
            window.document.first_form.the_textarea.value += word_with_return;
        }
    // show me -->
    </script>

    前幾行是典型的JavaScript預(yù)定義。主體中的第1行

    var word_with_return = the_word + "\n";

    將一個(gè)變量word_with_return進(jìn)行初始化為函數(shù)處理后的字符串并加上換行符"\n".。注意"\n" 是標(biāo)準(zhǔn)的計(jì)算機(jī)指令。

    下一行

    window.document.first_form.the_textarea.value += word_with_return;

    將文字區(qū)域的值設(shè)置為其原值加新變量。其作用相當(dāng)于

    window.document.first_form.the_textarea.value = window.document.first_form.the_textarea.value + word_with_return;

    目前我們已經(jīng)學(xué)習(xí)了文字域和文字區(qū)域(值)的屬性,接下來(lái)我們學(xué)習(xí)文字域和文字區(qū)域處理所用的方法:blur()、focus()和select()。

    下面的鏈接顯示了focus() 和select()如何工作。注意他們工作一次后可能會(huì)終止功能。

   

    Mouseover to focus Mouseover to select

    以下為表單和鏈接的編碼:

    <form name="method_form">
        <input type="text" name="method_text" size=40 value="Hey, hey, we're the monkeys">
    </form>

    <a href="#" onMouseOver="window.document.method_form.method_text.focus();">Mouseover to focus</a>
    <a href="#" onMouseOver="window.document.method_form.method_text.select();">Mouseover to select</a>

    其使用方法和調(diào)用任何對(duì)象方法的做法是一樣的:object_name.method(). 該文字域的名稱是window.document.form_name.text_field_name,所以用下列語(yǔ)句就可調(diào)用文字域的focus()方法。 

    window.document.method_form.method_text.focus();

相關(guān)文章

最新評(píng)論

宁晋县| 福泉市| 闵行区| 安康市| 鄄城县| 基隆市| 芦溪县| 西昌市| 格尔木市| 五大连池市| 宜阳县| 马尔康县| 绿春县| 吉隆县| 武汉市| 金寨县| 呼玛县| 盱眙县| 浦东新区| 彩票| 肃南| 西昌市| 汕头市| 苏尼特左旗| 调兵山市| 扎鲁特旗| 彩票| 黄平县| 阿城市| 乌恰县| 九龙县| 开封市| 吉木乃县| 化隆| 江陵县| 科尔| 井冈山市| 吉林省| 崇阳县| 福海县| 当涂县|