jqueryeasyui的form插件使用--form('reset') 和form('clear')

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Basic CRUD Application - jQuery EasyUI CRUD Demo</title>
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="http://oss.maxcdn.com/jquery.form/3.50/jquery.form.min.js"></script>
</head>
<body>
    <h2>Basic CRUD Application</h2>
    <p>Click the buttons on datagrid toolbar to do crud actions.</p>
    
    <table id="dg" title="My Users" class="easyui-datagrid" style="width:700px;height:250px"
            url="get_users.php"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr>
                <th field="firstname" width="50">First Name</th>
                <th field="lastname" width="50">Last Name</th>
                <th field="phone" width="50">Phone</th>
                <th field="email" width="50">Email</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>
    </div>
    
    <div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <h3>User Information</h3>
			<input type="hidden" name="id" id="id">
            <input type="hidden" name="recomBitType" id="recomBitType" value="1">
			
            <div style="margin-bottom:10px">
                <input name="firstname" class="easyui-textbox" required="true" label="First Name:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="lastname" class="easyui-textbox" required="true" label="Last Name:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="phone" class="easyui-textbox" required="true" label="Phone:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="email" class="easyui-textbox" required="true" validType="email" label="Email:" style="width:100%">
            </div>
			<div style="margin-bottom:10px">
                    <label>上架时间:</label>
                    <input id="lowershelfTime1" name="lowershelfTime1" class="easyui-datebox" style="width:100%" data-options="required:true,editable:false"  style="width:162px"/>
            </div>
			<div style="margin-bottom:10px">
                    <label>下架时间:</label>
                    <input id="lowershelfTime" name="lowershelfTime" class="easyui-datetimebox" style="width:100%" data-options="required:true,editable:false" style="width:162px"/>
            </div>
			<div style="margin-bottom:10px">
                    <label class=" acti">排序:</label>
                    <input class="input_text easyui-numberbox" name="priority" id="priority" style="width: 200px" data-options="required:true,min:1,max:100"/>
            </div>
			<div style="margin-bottom:10px">
                    <label>一句话描述:</label>
                    <input class="input_text easyui-validatebox" id="description" name="description" style="width:240px;"  data-options="required:true,validType:'maxLength[15]' "/>
            </div>
			<div class="form_list form_list_length">
				<label style="height: 60px">任务描述</label> <input class="easyui-textbox"
					name="jobDescription" data-options="multiline:true"
					style="width: 500px; height: 50px"></input>
			</div>
			 <div class="form_list" id="adtype_id">
				<label>广告类型:</label>
				<span  style="line-height: 35px;">
					<label style='width:auto; background:none; border:none;padding:1px 1px 0 0' for='advertisingType1'>
						<input type="radio" name="advertisingType" id="advertisingType1" value="1" checked="checked"/>单条
					</label>
					<label style='width:auto; background:none; border:none;padding:1px 1px 0 0' for='advertisingType2'>
						<input type="radio" name="advertisingType" id="advertisingType2" value="2" />多条
					</label>
				</span>
			</div>
			
			<div style="margin-bottom:10px">
				<input class="easyui-combobox" name="habbit"  data-options="
					valueField: 'label',
					textField: 'value',
					data: [{
						label: 'java',
						value: 'Java'
					},{
						label: 'perl',
						value: 'Perl'
					},{
						label: 'ruby',
						value: 'Ruby'
					}]" />
			  </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="cancleUser()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>
    <script type="text/javascript">
        var url;
        function newUser(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
            url = 'save_user.php';
			console.log($("#fm").serialize())
		}
        function editUser(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
                $('#fm').form('load',row);
                url = 'update_user.php?id='+row.id;
            }
        }
        function saveUser(){
			$("#recomBitType").val("666");
			$('#dlg').dialog('close');
			console.log($("#fm").serialize())
			//$('#fm').form('clear');
			$('#fm').resetForm(); //easyui-datetimebox easyui-textbox easyui-numberbox easyui-datebox失效  easyui-validatebox能清除
        }
		function cancleUser(){
		   $("#recomBitType").val("666");
		   $('#dlg').dialog('close');
           console.log($("#fm").serialize())
		   $('#fm').form('reset');//form('clear') 和jq中的resetForm()和clearForm区别类似
        }
        function destroyUser(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
                    if (r){
                        $.post('destroy_user.php',{id:row.id},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>
</body>
</html>

jQuery EasyUI 表单插件 - Form 表单

$('#fm').form('validate'); 进行表单字段验证,当全部字段都有效时返回 true 。该方法和 validatebox 插件一起使用。
$('#fm').form('clear');  清除表单数据。
$('#fm').form('reset'); 重置表单数据。该方法自版本 1.3.2 起可用

$('#fm').resetForm() 清除jqeasyui表单有些字段无法清除 例如 easyui-datetimebox easyui-textbox easyui-numberbox easyui-datebox  一般使用$('#fm').form('reset')即可,有隐藏域的  $("input[type='hidden']").val('')重置即可

 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值