如何使用jQuery做表单

如何使用jQuery做表单,第1张

html:

<div id="grid"></div>

js:

$("#grid").datagrid({

width: 600,

height: 400,

columns: [

{ text: "名称", field: "name", width: 200 },

{ text: "年龄", field: "age" },

{ text: "日期", field: "birthday",

renderer: function (value, row, col) {                    if (value &&value.getFullYear) {

value = value.getFullYear() + "-" + (value.getMonth() + 1) + "-" + value.getDate()

}                    return value

}

}

],

data: [

{ name: "name1", age: 20, birthday: new Date() },

{ name: "name1", age: 20, birthday: new Date() },

{ name: "name1", age: 20, birthday: new Date() },

{ name: "name1", age: 20, birthday: new Date() },

{ name: "name1", age: 20, birthday: new Date() }

]

})   function addRow() {        var grid = $("#grid").data("datagrid")

grid.addRow({ name: "bbb" })

}    function setColumns() {

var grid = $("#grid").data("datagrid")

grid.setColumns([

{ text: "Name", field: "name", width: 150 },

{ text: "Age", field: "age", width: 150 }

])

}

jquery提交表单有两种情况:

1:jquery只做提交用。

$("form").submit()

这个的表单提交到什么地方的是更具form元素里面的action属性去定义的。

2:jquery用ajax提交数据。

$.ajax({

type:"post",

url:"xxx.php", // 这里是提交到什么地方的url

data:{},// 这里把表单里面的数据放在这里传到后台

dataType:"json",

success:function(res){

// 调用回调函数

}

})


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11226890.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存