我试图实现类似于37signals的ta-da列表的效果 – 我希望我的用户能够通过检查“完成”框从列表中检查项目 – 换句话说,一个表单被提交到服务器在检查框.有没有人知道一个涵盖这样的教程,还是指向正确的方向?
谢谢
抢
解决方法
如果我正确理解你的问题:
您可以使用jQuery和AJAX完成此操作.在第一个示例中,我没有提交整个表单,只提交复选框的值:
jQuery("#myCheckBox").click(function() {
var $checkBox = jQuery(this);
var checkBoxData = "checkBoxvalue=" + $checkBox.val();
jQuery.ajax({
url: "http://some.url.here",type: "POST",data: checkBoxData,cache: false,dataType: "json",success: function(data) {
if(data["success"]) {
//do some other stuff if you have to
//this is based on the assumption that you're sending back
//JSON data that has a success property defined
}
}
});
});
大概你会有一些在服务器端处理这个职位.
如果您确实想要提交表单,您可以执行与上述相同的操作,除非您将表单数据序列化:
jQuery("#myCheckBox").click(function() {
var formData = jQuery("#formID").serialize();
jQuery.ajax({
url: "http://some.url.here",data: formData,success: function(data) {
if(data["success"]) {
//do some other stuff if you have to
//this is based on the assumption that you're sending back
//JSON data that has a success property defined
}
}
});
});