<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 0,  comments - 5,  trackbacks - 0
    dwr
    DWR 處理各種form表單Select/option,table

    util.js包含一些有用的函數(shù)function,用于在客戶端頁面調(diào)用.

    主要功能如下:

    代碼

    1、$() 獲得頁面參數(shù)值
    2、addOptions and removeAllOptions 初始化下拉框
    3、addRows and removeAllRows 填充表格
    4、getText 取得text屬性值
    5、getValue 取得form表單值
    6、getValues 取得form多個值
    7、onReturn
    8、selectRange
    9、setValue
    10、setValues
    11、toDescriptiveString
    12、useLoadingMessage
    13、Submission box

    代碼

    1、$()函數(shù)
    IE5.0 不支持
    $ = document.getElementById
    取得form表單值
    var name = $("name");

    代碼

    a、如果你想在更新select 時,想保存原來的數(shù)據(jù),即在原來的select中添加新的option:
    var sel = DWRUtil.getValue(id);
    DWRUtil.removeAllOptions(id);
    DWRUtil.addOptions(id,...);
    DWRUtil.setValue(id,sel);
    demo:比如你想添加一個option:“--請選擇--”
    DWRUtil.addOptions(id,["--請選擇--"]);

    DWRUtil.addOptions()有5中方式:

    代碼

    @ Simple Array Example: 簡單數(shù)組
    例如:
    Array array = new Array[ 'Africa', 'America', 'Asia', 'Australasia', 'Europe' ];
    DWRUtil.addOptions("demo1",array);

    代碼

    @ Simple Object Array Example 簡單數(shù)組,元素為beans
    這種情況下,你需要指定要顯示 beans 的 property 以及 對應(yīng)的 bean 值
    例如:
    public class Person {
    private String name;
    private Integer id;
    pirvate String address;
    public void set(){……}
    public String get(){……}
    }
    DWRUtil.addOptions("demo2",array,'id','name');
    其中id指向及bean的id屬性,在optiong中對應(yīng)value,name指向bean的name屬性,對應(yīng)下拉框中顯示的哪個值.

    代碼

    @ Advanced Object Array Example 基本同上
    DWRUtil.addOptions( "demo3",
    [{ name:'Africa', id:'AF' },
    { name:'America', id:'AM' },
    { name:'Asia', id:'AS' },
    { name:'Australasia', id:'AU' },
    { name:'Europe', id:'EU' }
    ],'id','name');

    代碼

    @ Map Example 用制定的map來填充 options:
    如果 server 返回 Map,呢么這樣處理即可:
    DWRUtil.addOptions( "demo3",map);
    其中 value 對應(yīng) map keys,text 對應(yīng) map values;

    代碼

    @ <ul> and <ol> list editing

    DWRUtil.addOptions() 函數(shù)不但可以填出select,開可以填出<ul>和<ol>這樣的heml元素

    3、addRows and removeAllRows 填充表格

    DWR 提供2個函數(shù)來操作 table;

    ----------------------------

    DWRUtil.addRows(); 添加行

    ----------------------------

    DWRUtil.removeAllRows(id); 刪除指定id的table

    ----------------------------

    下面著重看一下 addRows() 函數(shù):

    DWRUtil.addRows(id, array, cellfuncs, [options]);

    其中id 對應(yīng) table 的 id(更適合tbodye,推薦使用 tbodye)

    array 是server端服務(wù)器的返回值,比如list,map等等

    cellfuncs 及用返回值來天春表格

    [options] 用來設(shè)置表格樣式,它有2個內(nèi)部函數(shù)來設(shè)置單元格樣式(rowCreator、cellCreator)。

    比如: server端返回list,而list中存放的是下面這個 bean:

    代碼

    public class Person {
    private String name;
    private Integer id;
    pirvate String address;
    public void set(){……}
    public String get(){……}
    }

    下面用 DWRUtil.addRows();

    代碼

    function userList(data){
    //var delButton = "<input type='button'/>";
    //var editButton = "<input type='button'/>";
    var cellfuncs = [
    function(data){return data.id;},
    function(data){return data.userName;},
    function(data){return data.userTrueName;},
    function(data){return data.birthday;},
    function(data){
    var idd = data.id;
    var delButton = document.createElement("<INPUT TYPE='button' onclick='delPerson("+ idd +")'>");
    delButton.setAttribute("id","delete");
    delButton.setAttribute("value","delete");
    return delButton;
    },
    function(data){
    var idd = data.id;
    var editButton = document.createElement("<INPUT TYPE='button' onclick='editPerson("+ idd +")'>");
    editButton.setAttribute("name","edit");
    editButton.setAttribute("value","edit");
    return editButton;
    }
    ];
    DWRUtil.removeAllRows('tabId');
    DWRUtil.addRows('tabId', data,cellfuncs,{
    rowCreator:function(options) {
    var row = document.createElement("tr");
    var index = options.rowIndex * 50;
    row.setAttribute("id",options.rowData.id);
    row.style.collapse = "separate";
    row.style.color = "rgb(" + index + ",0,0)";
    return row;
    },
    cellCreator:function(options) {
    var td = document.createElement("td");
    var index = 255 - (options.rowIndex * 50);
    //td.style.backgroundColor = "rgb(" + index + ",255,255)";
    td.style.backgroundColor = "menu";
    td.style.fontWeight = "bold";
    td.style.align = "center";
    return td;
    }
    });
    document.getElementById("bt").style.display = "none";
    }

    4、getText 取得text屬性值

    DWRUtil.getText(id): 用來獲得 option 中的文本

    比如:

    代碼

    <select id="select">
    <option value="1"> 蘋果 </option>
    <option value="2" select> 香蕉 </option>
    <option value="3"> 鴨梨 </option>
    </select>

    調(diào)用 DWRUtil.getText("select"); 將返回 "香蕉" 字段;

    DWRUtil.getText(id);僅僅是用來獲得 select 文本值,其他不適用。

    5、DWRUtil.getValue(id): 用來獲得 form 表單值

    有如下幾種情況:

    代碼

    Text area (id="textarea"): DWRUtil.getValue("textarea")將返回 Text area的值;
    Selection list (id="select"): DWRUtil.getValue("select") 將返回 Selection list 的值;
    Text input (id="text"): DWRUtil.getValue("text") 將返回 Text input 的值;
    Password input (id="password"): DWRUtil.getValue("text") 將返回 Password input 的值;
    Form button (id="formbutton"): DWRUtil.getValue("formbutton") 將返回 Form button 的值;
    Fancy button (id="button"): DWRUtil.getValue("formbutton") 將返回 Fancy button 的值;

    6、getValues 取得form多個值

    批量獲得頁面表單的值,組合成數(shù)組的形式,返回 name/value;

    例如: form():

    代碼

    <input type="textarea" id="textarea" value="1111"/>
    <input type="text" id="text" value="2222"/>
    <input type="password" id= "password" value="3333"/>
    <select id="select">
    <option value="1"> 蘋果 </option>
    <option value="4444" select> 香蕉 </option>
    <option value="3"> 鴨梨 </option>
    </select>
    <input type="button" id="button" value="5555"/>

    那么: DWRUtil.getValues({textarea:null,select:null,text:null,password:null,button:null})
    將返回 ^^^^^^^^^^^^^^^^{textarea:1111,select:4444,text:2222,password:3333,button:5555}

    7、DWRUtil.onReturn 防止當(dāng)在文本框中輸入后,直接按回車就提交表單。

    <input type="text" onkeypress="DWRUtil.onReturn(event, submitFunction)"/>

    <input type="button" onclick="submitFunction()"/>

    8、DWRUtil.selectRange(ele, start, end);

    在一個input box里選一個范圍

    代碼

    DWRUtil.selectRange("sel-test", $("start").value, $("end").value);

    比如:<input type="text" id="sel-test" value="012345678901234567890">

    DWRUtil.selectRange("sel-test", 2, 15);

    9、DWRUtil.setValue(id,value);

    為指定的id元素,設(shè)置一個新值;

    10、DWRUtil.setValues({

    name: "fzfx88",

    password: "1234567890"

    }

    ); 同上,批量更新表單值.

    /***********************************************************************/

    11、DWRUtil.toDescriptiveString()

    帶debug信息的toString,第一個為將要debug的對象,第二個參數(shù)為處理等級。等級如下:

    0: Single line of debug 單行調(diào)試

    1: Multi-line debug that does not dig into child objects 不分析子元素的多行調(diào)試

    2: Multi-line debug that digs into the 2nd layer of child objects 最多分析到第二層子元素的多行調(diào)試

    <input type="text" id="text">

    DWRUtil。toDescriptiveString("text",0);

    /******************************************************************************/

    12、DWRUtil.useLoadingMessage();

    當(dāng)發(fā)出ajax請求后,頁面顯示的提示等待信息;

    代碼

    function searchUser(){
    var loadinfo = "loading....."
    try{
    regUser.queryAllUser(userList);
    DWRUtil.useLoadingMessage(loadinfo);
    }catch(e){

    }
    }
    posted on 2008-06-12 10:15 crazy 閱讀(188) 評論(0)  編輯  收藏 所屬分類: javasrcipt
    主站蜘蛛池模板: 美女的胸又黄又www网站免费| 亚洲视频一区调教| 亚洲AV综合色区无码一二三区| 97人妻无码一区二区精品免费| 亚洲视频一区在线| 最近2019免费中文字幕6| 91亚洲va在线天线va天堂va国产| 日韩精品免费在线视频| 久久亚洲AV成人无码电影| 在线观看免费毛片| 欧洲 亚洲 国产图片综合| 久久这里只有精品国产免费10| 亚洲 暴爽 AV人人爽日日碰| 妞干网免费视频在线观看| 亚洲日韩AV一区二区三区四区| 日韩特黄特色大片免费视频| 国产成人综合久久精品亚洲| 亚洲国产天堂久久综合| 亚洲人成网站日本片| AV片在线观看免费| 性色av极品无码专区亚洲| 免费在线黄色网址| a级毛片100部免费观看| 亚洲欧洲日产国码在线观看| 大学生高清一级毛片免费| 高潮内射免费看片| 亚洲av鲁丝一区二区三区| 国产在线观看片a免费观看| 亚洲hairy多毛pics大全| 国内精品99亚洲免费高清| 国产精品免费福利久久| 亚洲中文字幕无码av| 亚洲第一视频在线观看免费| a级毛片免费观看视频| 国产v亚洲v天堂a无| 亚洲欧洲日本在线| 每天更新的免费av片在线观看| 亚洲人成色在线观看| 亚洲国产精品无码专区| 一二三四免费观看在线电影| 无码人妻一区二区三区免费视频|