ExtJs 备忘录(2)—— Form表单(二) [ 控件封装 ]

前言
  本以为可以稳稳当当的工作、安安心心的写文章,结果我做了一件非常疯狂的事情,换新工作一周后辞了——然后去了另外一家公司 - - #,理由就不详说了,总之现在是每天加班到8-9点,虽然如此但是这个团队非常棒,喜欢这里的气氛,大家都努力的工作着,经理也是常睡在公司,希望产品顺顺利利的月底上线,我也加油 !不过这样一来文章可能会慢点,挤挤时间吧:  )
  本篇主要是将对Ext常用控件和属性进行封装,以减少动辄几百行的JS代码,也方便使用。

系列
  1.  ExtJs 备忘录(1)—— Form表单(一) [ 控件使用 ]
  2.  ExtJs 备忘录(2)—— Form表单(二) [ 控件封装 ]

正文
  一、使用封装后Ext表单控件
    esayadd.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="esayadd.aspx.cs" Inherits="esayadd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>表单控件</title>
</head>
<body>
    <form id="form1" runat="server">
<script type="text/javascript">
    Ext.onReady(function() {
    
        Ext.QuickTips.init();
        Ext.form.Field.prototype.msgTarget = 'side';

        var form1 = new Ext.FormPanel({
            layout: 'form',
            collapsible: true,
            autoHeight: true,
            frame: true,
            renderTo: Ext.getBody(),
            title: '<center style="curor:hand" onclick="window.location.reload();">表单控件</center>',
            style: 'margin-left:auto;margin-right:auto;width:500px;margin-top:8px;',
            //设置标签对齐方式
            labelAlign: 'right',
            //设置标签宽
            labelWidth: 170,
            //设置按钮的对齐方式
            buttonAlign:'center',
            //默认元素属性设置
            defaults:{
                    width:180
                },
            items: [
                new TextField('TextBox','文本框控件'),
                new NumberField('TextBoxNumber','只允许输入数字'),
                new ComboBox('DropDownList','下拉框控件',[[1,'男'],[0,'女']]),
                new DateField('DateControl','日历控件'),
                new RadioGroup('RadioItems','单选控件',[['选我','A',true],['选我吧','B']]),
                new CheckboxGroup('CheckboxItems','复选控件',[['香蕉','A'],['苹果','B'],['橘子','C'],['桃子','D']],3),
                new TextArea('textarea','文本域控件',null,50,'可以输好多字!'),
                new TimeField(null,'时间控件',60,'H:i'),
                new FieldSet('标签页','标签页',[new Panel('标签页中的面板',null,50,true)]),
                new HtmlEditor('htmleditor','在线编辑器',260,100)
            ],
            buttons: [{
                text: "保 存"
                ,handler:function(){
                    MsgError('错误');
                    MsgWarning('警告');
                    MsgInfo('提示');
                    MsgConfirm('确认');
                }
            }, {
                text: "取 消"
                ,handler:function(){
                    form1.form.reset();
                }
            }]
        });
    });
    </script>
    </form>
</body>
</html>

    代码说明:
      请大家比较ExtJs 备忘录(1)—— Form表单(上) [ 控件使用 ]中的add.aspx与本文esayadd.aspx,封装带来的简洁、易用和减少使用控件出错几率是显而易见的。需要注意的是,这里只是做了简单的封装,因为Ext表单控件属性太多,起码也有10个以上,这里不可能把所有的属性都列为函数参数,所以根据实际项目情况进行调整,可以在这个现有函数基础上补上常用的参数设置,只要能满足80%-90%的情况价值就体现了 : )

  二、Ext表单控件封装
    easy-ext.js    


/// <reference path="../adapter/ext/ext-base.js" />
/// <reference path="../ext-all.js" />

//<><><><><><><><><><><><><><><><><><><><>
// 作 者:农民伯伯
// 邮 箱:over140@gmail.com
// 博 客:http://over140.cnblogs.com/
// 时 间:2009-9-16
//<><><><><><><><><><><><><><><><><><><><>

//#region Ext.form.TextField
function TextField(fName,fLabel,defaultValue)
{
    /// <summary>
    /// Ext.form.TextField封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="defaultValue">默认值</param>
    /// <returns>Ext.form.TextField</returns>
    var text = new Ext.form.TextField();
    
    if(fName!=null)
        text.name = fName;
    
    if(fLabel!=null)
        text.fieldLabel = fLabel;
    
    //设置默认值
    if(defaultValue != null)
        text.setValue(defaultValue);
    
    return text;
}
//#endregion

//#region Ext.form.TextField
function NumberField(fName,fLabel,defaultValue,allowDecimals,allowNegative,maxValue,minValue)
{
    /// <summary>
    /// Ext.form.NumberField封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="defaultValue">默认值</param>
    /// <param name="allowDecimals">是否允许小数点</param>
    /// <param name="allowNegative">是否允许负数</param>
    /// <param name="maxValue">最大值</param>
    /// <param name="minValue">最小值</param>
    /// <returns>Ext.form.NumberField</returns>
    var number = new Ext.form.NumberField();
    
    if(fName!=null)
        number.name = fName;
    
    if(fLabel!=null)
        number.fieldLabel = fLabel;
    
    //设置默认值
    if(defaultValue != null && typeof(defaultValue) == "number")
        number.setValue(defaultValue);
    
    //设置是否允许小数点,默认(不设置)为不允许
    if(allowDecimals != null && typeof(allowDecimals) == "boolean")
        number.allowDecimals = Boolean(allowDecimals);
        
    //设置是否允许负数,默认(不设置)为不允许
    if(allowNegative != null && typeof(allowNegative) == "boolean")
        number.allowNegative = Boolean(allowNegative);     
    
    //设置最大值
    if(maxValue != null && typeof(maxValue) == "number")
        number.maxValue = Number(maxValue);     
        
    //设置最小值
    if(minValue != null && typeof(minValue) == "number")
        number.minValue = Number(minValue);
    
    return number;
}
//#endregion

//#region Ext.form.DateField
function DateField(fName,fLabel,defaultValue,format,editable)
{
    /// <summary>
    /// Ext.form.DateField封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="defaultValue">Boolean:true为当前日期/String: 按'Y-m-d'格式,如2009-1-1</param>
    /// <param name="format">设置日期格式化字符串</param>
    /// <param name="editable">是否允许输入,还是只能选择日期</param>
    /// <returns>Ext.form.DateField</returns>
    var date = new Ext.form.DateField();
    
    if(fName!=null)
        date.name = fName;
    
    if(fLabel!=null)
        date.fieldLabel = fLabel;
    
    //设置日期格式化字符串
    if(format == null)
        format = 'Y-m-d';
    date.format = format;
    
    //设置默认日期
    if(defaultValue != null)
    {
        if(typeof(defaultValue) == "boolean" && Boolean(defaultValue) == true)
        {
            date.setValue(new Date().dateFormat(format));
        }
        else if(typeof(defaultValue) == "string")
        {
            var strDate =String(defaultValue).split("-");
            if(strDate.length==3)
                date.setValue(new Date(strDate[0],parseInt(strDate[1])-1,strDate[2]).dateFormat(format));
        }
    }
    
    //是否允许编辑
    if(editable==null)
        editable = false;
    else if(typeof(editable) == "boolean")
        editable = Boolean(editable);
    
    date.editable = editable;
    
    return date;
}
//#endregion

//#region Ext.form.TimeField

function TimeField(fName,fLabel,increment,format)
{
    /// <summary>
    /// Ext.form.TimeField封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="increment">设置时间间隔,单位为分钟</param>
    /// <param name="format">格式化输出,支持格式如下:"g:ia|g:iA|g:i a|g:i A|h:i|g:i|H:i|ga|ha|gA|h a|g a|g A|gi|hi|gia|hia|g|H"</param>
    /// <returns>Ext.form.TimeField</returns>
    var time = new Ext.form.TimeField();
    
    if(fName!=null)
        time.name = fName;
    
    if(fLabel!=null)
        time.fieldLabel = fLabel;
        
    //设置时间间隔 默认为15分钟
    if(increment!=null && typeof(increment) == "number")
        time.increment = Number(increment);
        
    //设置格式化输出 默认为 "g:i A"
    if(format != null && typeof(format) == "string")
        time.format = String(format);
    
    return time;
}

//#endregion

//#region Ext.form.ComboBox
function ComboBox(fName,fLabel,dataStore,defaultValue,displayField,valueField,editable)
{
    /// <summary>
    /// Ext.form.ComboBox封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="dataStore">数据源。本地模式,如[[1,'男'],[0,'女']];远程模式,传入Ext.data.Store</param>
    /// <param name="defaultValue">默认值</param>
    /// <param name="displayField">选项的文本对应的字段</param>
    /// <param name="valueField">选项的值对应的字段</param>
    /// <param name="editable">是否可以输入,还是只能选择下拉框中的选项</param>
    /// <returns>Ext.form.ComboBox</returns>
    var combo = new Ext.form.ComboBox({
        mode: 'local',
        editable : false,
        typeAhead: true,
        triggerAction: 'all',
        selectOnFocus:true
    });
    
    if(fName!=null)
        combo.name = fName;
    
    if(fLabel!=null)
        combo.fieldLabel = fLabel;
        
    if(displayField==null || typeof(displayField) != "string")
        displayField = "Name";
    combo.displayField = String(displayField);
        
    if(valueField==null || typeof(valueField) != "string")
        valueField = "Id";
    combo.valueField = String(valueField);    
    
    //设置数据源
    if(Ext.isArray(dataStore))
    {
        combo.store = new Ext.data.SimpleStore({
            fields: [valueField, displayField],
            data:dataStore
        });
    }
    else
    {
        combo.store = dataStore;
        combo.mode = 'remote';
    }
    
    //设置默认值
    if(defaultValue!=null)
        combo.setValue(defaultValue);
    
    //是否允许编辑
    if(editable!=null && typeof(editable) == "boolean")
        combo.editable = Boolean(editable);  
    
    return combo;
}
//#endregion

//#region Ext.form.TextArea

function TextArea(fName,fLabel,width,height,value)
{
    /// <summary>
    /// Ext.form.TextArea封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="width">width</param>
    /// <param name="height">height</param>
    /// <param name="value">value</param>
    /// <returns>Ext.form.TextArea</returns>
    var area = new Ext.form.TextArea();

    if(fName!=null)
        area.name = fName;
    
    if(fLabel!=null)
        area.fieldLabel = fLabel;
        
    if(width!=null && typeof(width) == "number")
        area.width = Number(width);
        
    if(height!=null && typeof(height) == "number")
        area.height = Number(height);
        
    if(value!=null)
        area.value = value;
        
    return area;
}

//#endregion

//#region Ext.form.RadioGroup

function RadioGroup(fName,fLabel,items,columns)
{
    /// <summary>
    /// Ext.form.RadioGroup封装
    ///     例子:new RadioGroup('Gender','性别',[['男','男',true],['女','女']])
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="items">数据,格式如下:[['男','男',true],['女','女']]</param>
    /// <param name="columns">设置几列自动排列,如果是1的话会按一行来显示</param>
    /// </summary>
    /// <returns>Ext.form.RadioGroup</returns>
    var rg = new Ext.form.RadioGroup();
    
    if(fName!=null)
        rg.name = fName;
    
    if(fLabel!=null)
        rg.fieldLabel = fLabel;
    
    if(columns!=null && typeof(columns) == "number")
        rg.columns = Number(columns);
        
    var rebuildiItems = new Array();
        
    if(items !=null){
        for(var i = 0 ;i<items.length; i++)
        {
            rebuildiItems[i] = {};
            rebuildiItems[i].name = fName;
            rebuildiItems[i].boxLabel = items[i][0];
            rebuildiItems[i].inputValue = items[i][1];
            if(items[i].length > 2 && typeof(items[i][2]) == "boolean")
                rebuildiItems[i].checked = Boolean(items[i][2]);
        }
        
        //Ext.form.RadioGroup扩展
        Ext.override(Ext.form.CheckboxGroup, {
            setItems:function(data){
                this.items = data;
            }
        });

        if(rg.setItems){
            rg.setItems(rebuildiItems);
        }        
    }
    
    return rg;
}

//#endregion

//#region Ext.form.CheckboxGroup

function CheckboxGroup(fName,fLabel,items,columns)
{
    /// <summary>
    /// Ext.form.CheckboxGroup封装
    ///     例子:new CheckboxGroup('Gender','性别',[['男','男',true],['女','女']])
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="items">数据,格式如下:[['男','男',true],['女','女']]</param>
    /// <param name="columns">设置几列自动排列,如果是1的话会按一行来显示</param>
    /// </summary>
    /// <returns>Ext.form.CheckboxGroup</returns>
    var cg = new Ext.form.CheckboxGroup();
    
    if(fName!=null)
        cg.name = fName;
    
    if(fLabel!=null)
        cg.fieldLabel = fLabel;
    
    if(columns!=null && typeof(columns) == "number")
        cg.columns = Number(columns);
        
    var rebuildiItems = new Array();
        
    if(items !=null){
        for(var i = 0 ;i<items.length; i++)
        {
            rebuildiItems[i] = {};
            rebuildiItems[i].name = fName;
            rebuildiItems[i].boxLabel = items[i][0];
            rebuildiItems[i].inputValue = items[i][1];
            if(items[i].length > 2 && typeof(items[i][2]) == "boolean")
                rebuildiItems[i].checked = Boolean(items[i][2]);
        }
        
        //Ext.form.RadioGroup扩展
        Ext.override(Ext.form.CheckboxGroup, {
            setItems:function(data){
                this.items = data;
            }
        });

        if(cg.setItems){
            cg.setItems(rebuildiItems);
        }        
    }
    
    return cg;
}

//#endregion

//#region Ext.form.HtmlEditor

function HtmlEditor(fName,fLabel,width,height,value)
{
    /// <summary>
    /// Ext.form.HtmlEditor封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="width">width</param>
    /// <param name="height">height</param>
    /// <param name="value">value</param>
    /// <returns>Ext.form.HtmlEditor</returns>
    var editor = new Ext.form.HtmlEditor();

    if(fName!=null)
        editor.name = fName;
    
    if(fLabel!=null)
        editor.fieldLabel = fLabel;
        
    if(width!=null && typeof(width) == "number")
        editor.width = Number(width);
        
    if(height!=null && typeof(height) == "number")
        editor.height = Number(height);
        
    if(value!=null)
        editor.value = value;
        
    return editor;
}

//#endregion

//#region Ext.form.Hidden

function Hidden(fName,value)
{
    /// <summary>
    /// Ext.form.Hidden封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="value">value</param>
    /// <returns>Ext.form.Hidden</returns>
    var hidden = new Ext.form.Hidden();

    if(fName!=null)
        hidden.name = fName;
        
    if(value!=null)
        hidden.value = value;
        
    return hidden;
}

//#endregion

//#region Ext.form.Checkbox

function Checkbox(fName,fLabel,value,boxLabel,inputValue,checked)
{
    /// <summary>
    /// Ext.form.Checkbox封装
    /// </summary>
    /// <param name="fName">name</param>
    /// <param name="fLabel">fieldLabel</param>
    /// <param name="value">value</param>
    /// <param name="boxLabel"></param>
    /// <param name="inputValue"></param>
    /// <param name="checked"></param>
    /// <returns>Ext.form.Checkbox</returns>
    var checkbox = new Ext.form.Checkbox();

    if(fName!=null)
        checkbox.name = fName;
        
    if(fLabel!=null)
        checkbox.fieldLabel = fLabel;
        
    if(value!=null)
        checkbox.value = value;
        
    if(boxLabel!=null && typeof(boxLabel) == "string")
        checkbox.boxLabel = String(boxLabel);
    
    if(inputValue!=null)
        checkbox.inputValue = inputValue;
        
    if(checked!=null && typeof(checked) == "boolean")
        checkbox.checked = Boolean(checked);
        
    return checkbox;
}

//#endregion

//#region Ext.form.FieldSet

function FieldSet(fName,title,items)
{
    /// <summary>
    /// Ext.form.FieldSet封装
    /// </summary>
    /// <param name="fName">fieldLabel</param>
    /// <param name="title">title</param>
    /// <param name="items">数据源</param>
    /// <returns>Ext.form.FieldSet</returns>
    var fieldset = new Ext.form.FieldSet();
    
    if(fName!=null)
        fieldset.fieldLabel = fName;
        
    if(title!=null  && typeof(title) == "string")
        fieldset.title = String(title);
        
    if(items!=null)
        fieldset.add(items);
    
    return fieldset;
}

//#endregion

//#region Ext.Panel

function Panel(title,width,height,frame)
{
    /// <summary>
    /// Ext.Panel封装
    /// </summary>
    /// <param name="title">name</param>
    /// <param name="width">value</param>
    /// <param name="height">height</param>
    /// <param name="frame">frame</param>
    /// <returns>Ext.Panel</returns>
    if(title ==null)
        title = '';  //默认值 如果为此值则不显示标题栏
        
    var panel = new Ext.Panel({
        title:title
    });
        
    if(width!=null && typeof(width) == "number")
        panel.width = Number(width);
        
    if(height!=null && typeof(height) == "number")
        panel.height = Number(height);
        
    if(frame!=null && typeof(frame) == "boolean")
        panel.frame = Boolean(frame);
    
    return panel;
}

//#endregion

//#region MessageBox

function MsgConfirm(msg,title,fn,width)
{
    /// <summary>
    /// Ext.Msg.show 问题确认框
    /// </summary>
    /// <param name="msg">设置要输出的信息</param>
    /// <param name="title">设置确认框标题</param>
    /// <param name="fn">设置回调fn函数</param>
    /// <param name="width">设置确认框宽</param>
    /// <returns>Ext.Msg.show</returns>
    if(msg ==null)
        msg = "";
    
    if(title == null || typeof(title) != "string")
        title = "问题";
        
    if(width == null || typeof(width) != "number")
        width = 400;
        
    if(fn == null || typeof(fn) != "function")
        fn = new function(){};
    
    return Ext.Msg.show({
        title: title,
        msg: msg,
        width: width,
        icon:Ext.MessageBox.QUESTION,
        buttons: Ext.MessageBox.YESNO,
        fn:fn
    });
}

function MsgInfo(msg,title,width)
{
    /// <summary>
    /// Ext.Msg.show 信息提示框
    /// </summary>
    /// <param name="msg">设置要输出的信息</param>
    /// <param name="title">设置标题</param>
    /// <param name="width">设置提示框宽</param>
    /// <returns>Ext.Msg.show</returns>
    if(msg ==null)
        msg = "";
    
    if(title == null || typeof(title) != "string")
        title = "提示";
        
    if(width == null || typeof(width) != "number")
        width = 400;
        
    return Ext.MessageBox.show({
        title: title,
        msg: msg,
        width: width,
        icon:Ext.MessageBox.INFO,
        buttons: Ext.MessageBox.OK
    });
}

function MsgError(msg,title,width)
{
    /// <summary>
    /// Ext.Msg.show 错误提示框
    /// </summary>
    /// <param name="msg">设置要输出的信息</param>
    /// <param name="title">设置标题</param>
    /// <param name="width">设置提示框宽</param>
    /// <returns>Ext.Msg.show</returns>
    if(msg ==null)
        msg = "";
    
    if(title == null || typeof(title) != "string")
        title = "错误";
        
    if(width == null || typeof(width) != "number")
        width = 400;

    return Ext.MessageBox.show({
        title: title,
        msg: msg,
        width: width,
        icon:Ext.MessageBox.ERROR,
        buttons: Ext.MessageBox.OK
    });
}

function MsgWarning(msg,title,width)
{
    /// <summary>
    /// Ext.Msg.show 警告提示框
    /// </summary>
    /// <param name="msg">设置要输出的信息</param>
    /// <param name="title">设置标题</param>
    /// <param name="width">设置提示框宽</param>
    /// <returns>Ext.Msg.show</returns>
    if(msg ==null)
        msg = "";
    
    if(title == null || typeof(title) != "string")
        title = "警告";
        
    if(width == null || typeof(width) != "number")
        width = 400;

    return Ext.MessageBox.show({
        title: title,
        msg: msg,
        width: width,
        icon:Ext.MessageBox.WARNING,
        buttons: Ext.MessageBox.OK
    });
}

//#endregion

    代码说明:
      这里封装了常用的Form表单控件、Panel控件、以及弹出消息提示的封装。这里为什么要封装MSG框呢,根据我使用ext3.0rc2的经验,如果不指定MSG宽且MSG字符串过少的话可能出现对话框残缺的情况,不知道是不是它的BUG,3.0正式版好像没有这情况,但还是封装了,这样能兼容前面的版本。

  三、说明
    1.  写好封装js后,还需要把它加入到head里面,以便其他地方也能方便使用,注意上篇文章ExtHelper.cs我注释的部分,解除注释即可。注意这里文件名称可能有变化,对应修改即可。
    2.  封装的好处在贴esayadd.aspx代码后面的说明里面有说,对于动辄几百行的JS代码,这样还是能有效的减少代码量,也不容易出错。一旦封装好后就不要轻易修改了,如果要修改也必须保证只能增加参数,这样才能保证你前面写的代码调用没有问题,对于特殊的复杂的设置可以在封装的基础上继续设置(你可以看到return 都是Ext的对象)或者重新写一个可能比较好!

  四、下载
    1.  ExtJS2009-9-20.rar

结束语

  有点忙,今天不加班,所以也赶紧把这系列尽早写完吧:  )

转载:http://www.cnblogs.com/over140/archive/2009/09/20/1566010.html

时间: 2024-08-02 06:33:42

ExtJs 备忘录(2)—— Form表单(二) [ 控件封装 ]的相关文章

Drupal7 form表单二次开发要点与实例

 这篇文章主要介绍了Drupal7 form表单二次开发要点与实例,解决了经常使用的Form表单提交后跳转问题,需要的朋友可以参考下 请记得收藏此文,在你进行Drupal 7 custom module时,经常会用到的form 表单的跳转或重载.   主要汇总三个要点:   1.页面提交后,经过#submit处理后,需要redirect 跳转到另外一个页面. 2.url路径中存在destination参数时,页面直接跳转到destination所指的url,无法控制的问题. 3.form表单如何

jquery表单验证控件:Form-Validate例子

在做登录注册模块的时候, 我们需要要求用户按照我们的规则进行信息的填写, 如果直接在填写完成之后提交的时候验证这些信息的话, 对于用户来说不得不说是一个比较烂的体验, form-validate控件是一个超强大的表单验证控件, 包含了简单的规则验证, 异步验证等等, 并且该控件可以自定义验证规则.既方便又实用. 官网下载form-validate之后, 在页面上引入jquery.validate.min.js文件, 注意: 在这之前必须先引入Jquery库; <script src="/j

Drupal7 form表单二次开发要点与实例_php技巧

请记得收藏此文,在你进行Drupal 7 custom module时,经常会用到的form 表单的跳转或重载. 主要汇总三个要点: 1.页面提交后,经过#submit处理后,需要redirect 跳转到另外一个页面.2.url路径中存在destination参数时,页面直接跳转到destination所指的url,无法控制的问题.3.form表单如何实现multiple steps forms 多个步骤,或者表单提交后,如何在表单获取到提交上来的值. 一.Form 表单 redirect(跳转

asp.net夜话之三:表单和控件

在今天我主要要介绍的有如下知识点: HTML表单的提交方式 HTM控件 获取HTML表单内容 乱码问题 SQL注入 服务器端表单 HTML服务器控件 HTML表单的提交方式 对于一个普通HTML表单来说,它有两个重要的属性:action和method. action属性指明当前表单提交之后由哪个程序来处理,这个处理程序可以是任何动态网页或者servlet或者CGI(Common Gateway Interface),在asp.net里面一般都是都aspx页面来处理. method属性指明form

jQuery控制回车使表单内控件获得焦点

 <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(function(){        var length = $(":input").length;        $(":input").keyup(function

PHP表单递交控件名称含有点号(.)会被转化为下划线(_)的处理方法_php技巧

最近在做公司项目的时候,发现一个奇怪的问题,递交一个正常表单,竟然发现不能正常获取到递交的值,这一发现,不免让我开始的时候一头雾水,开始的时候一度认为是我的服务有问题,不能正常的写入数据库,后来侦测SQL语句发现,原来问题竟然出现在获取数据上,获取到的数据竟然都是空的,后来一调试发现,原来递交到后端的所有变量,都已经不是预期中的变量,竟然被PHP转化了. 提供测试代码如下: 复制代码 代码如下: <html> <head> <title>测试表单提交</title

java-ajax提交带有file标签的form表单

问题描述 ajax提交带有file标签的form表单 struts2中中有一个的标签,直接提交可以把文件名.等参数提交到后台.现在的问题的是有一个树形的文件列表界面,根节点是文件夹,子节点是文件,选中文件夹那一行然后点击右键会有个上传文件的菜单项,那么怎么将选中的那一行的属性和标签的文件名等属性一起提交到后台.有点啰嗦,不知道描述清楚了没有,求指点,感激不尽. 解决方案 将节点的信息放到表单hidden控件中,给表单指定target提交到隐藏iframe来实现文件上传,或者用jquery.for

jquery插件EasyUI中form表单提交实例分享_jquery

之前用AJax给Controller传递参数,然后再调用服务端的方法对数据库进行更改,今天碰到一个新的方法,就是表单的提交,这样可以省去AJax传参. 当表单提交后,我们可以获取表单上控件中的值,然后再调用服务端的方法对数据库进行更改.下面的一张截图是具体的业务需求. 一.要实现的功能:从上面这个表单中,获取控件中的值,然后传递给后台.下面是表单代码. 二.表单代码 <div id="Editwin" class="easyui-window" title=&

ExtJs 备忘录(1)—— Form表单(一) [ 控件使用 ]

前言 ExtJS接触至今已有4个月(5.1 - 9.1),小有心得,由于公司短期内并没有打算采用,所以备忘之以备他日之需.虽然网上资料不少,但学起来仍感费劲,所以还是想以自己的方式来与众分享. 系列 1. ExtJs 备忘录(1)-- Form表单(一) [ 控件使用 ] 版本 Ext 3.0.0 正文 一.效果图 先用美图勾引那些驻足观望之人: 二.代码讲解 如果项目中大量采用ExtJS做前端,我建议采用PageBase方式来引用和使用它. 2.1 目录结构 项目中使用Ext并不需要把整个Ex