用Json给表单赋值
$.extend({
setForm :function(frm,jsonValue) {
var obj=$(frm);
$.each(jsonValue, function (name, ival) {
var $oinput = obj.find("input[name=" + name + "]");
if ($oinput.attr("type")== "radio" || $oinput.attr("type")== "checkbox"){
$oinput.each(function(){
if(Object.prototype.toString.apply(ival) == '[object Array]'){// 是复选框,并且是数组
for(var i=0;i<ival.length;i++){
if($(this).val()==ival[i])
$(this).attr("checked", "checked");
}
}else{
if($(this).val()==ival)
$(this).attr("checked", "checked");
}
});
}else if($oinput.attr("type")== "textarea"){// 多行文本框
obj.find("[name="+name+"]").html(ival);
}else{
obj.find("[name="+name+"]").val(ival);
}
});
},
getFormJson:function(frm) {
var o = {};
var a = $(frm).serializeArray();
$.each(a, function() {
if (this.name == "password") {
//this.value = $.md5(this.value) //md5操作
this.value=this.value;
}
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [ o[this.name] ];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
});
以上是扩展
下面是调用方式:
$.setForm('#form1',jsonData);
以上内容转载自:https://www.cnblogs.com/cutone/p/7126094.html
用Json给表单赋值的更多相关文章
- httpclient模拟post请求json封装表单数据
好长时间不更博了,主要肚子里没什么好墨水,哈哈.废话不说上代码. public static String httpPostWithJSON(String url) throws Exception ...
- json化表单数据
/** * josn化表单数据 * @name baidu.form.json * @function * @grammar baidu.form.json(form[, replacer]) * @ ...
- Retrofit 2.0 轻松实现多文件/图片上传/Json字符串/表单
如果嫌麻烦直接可以用我封装好的库:Novate: https://github.com/Tamicer/Novate 通过对Retrofit2.0的前两篇的基础入门和案例实践,掌握了怎么样使用Retr ...
- 针对form表单赋值封装
1 (function ($){ 2 $.fn.extend({ 3 exajax:function(url,opts,convert){ 4 var ajaxParam = { 5 url:url, ...
- html 表单赋值 和 时间戳 转换
<script> window.onload = function () { var str; // console.log(@ViewBag.ID); $.post("/Ser ...
- Layui 表单赋值 编辑页面赋初值
原文:https://blog.csdn.net/yulongxue/article/details/97924591 //编辑 if (id > 0) { $.post("/Hand ...
- jq批量与表单赋值
function loadData(obj) { var key, value, tagName, type, arr; for (x in obj) { key = x; value = obj[x ...
- jquery form表单赋值封装
;!(function ($) { $.fn.setFormValue = function (options) { var $this = $(this); $.each(options, func ...
- vue自定义表单生成器,可根据json参数动态生成表单
介绍 form-create 是一个可以通过 JSON 生成具有动态渲染.数据收集.验证和提交功能的表单生成器.并且支持生成任何 Vue 组件.结合内置17种常用表单组件和自定义组件,再复杂的表单都可 ...
随机推荐
- electron串口通信使用serialport安装报错
1.报错信息没有安装python环境 1 gyp ERR! find Python 2 gyp ERR! find Python Python is not set from command line ...
- Java面向对象笔记 • 【第7章 集合】
全部章节 >>>> 本章目录 7.1 集合概述 7.1.1 Java集合体系概述 7.1.2 实践练习 7.2 List集合 7.2.1 ArrayList实现类 7.2. ...
- IPv6地址格式
1.说明 IPv6是互联网协议的第六版, 现有IPv4只支持大概40亿个网络地址, 而IPv6支持3.4e38个网络地址. IPv4的地址长度是32位(bit), IPv6的地址长度是128位. 尽管 ...
- 为什么要避免在 Go 中使用 ioutil.ReadAll?
原文链接: 为什么要避免在 Go 中使用 ioutil.ReadAll? ioutil.ReadAll 主要的作用是从一个 io.Reader 中读取所有数据,直到结尾. 在 GitHub 上搜索 i ...
- hexo 升级5.4.0出现错误解决方法-hexo-theme-butterfly
本篇文章已同步个人博客,可移步食用.hexo 升级 5.4.0 出现错误解决方法 -hexo-theme-butterfly 周末升级了下 hexo 到新版本,发现升级后,构建时出现了一些错误,以下是 ...
- JDK_win10环境下安装JDK8时点击下一步没反应的解决办法
问题现象 打开JDK8,点击下一步就没后续了... 解决方法 百度了一下"win10安装jdk8点下一步无响应" . 按照博客中说的操作试了下...安装成功了... 只想说...什 ...
- JQuery实现奇偶行不同背景颜色
假设table的id为:t1 $(document).ready(function(){ $('#t1 > tbody tr:even').css('background','white'); ...
- 虚拟机上CentOS7环境配置
原文链接:https://www.toutiao.com/i6493449649939022350/ 之前网络和基本环境以及完成,现在我们再配置一些内容,方便我们之后的学习. 设置网络YUM源 下载我 ...
- PPT制作图片磨砂玻璃艺术效果
如果图片损害,点击链接:https://www.toutiao.com/i6488928834799272462/ 选择"插入"选项卡,"图像"功能组,&quo ...
- Vue项目中使用websocket
<template> <div class="test"> </div> </template> <script> ex ...