复选框 - 选中或取消选中使用jQuery和MySQL [英] checkbox - checked or unchecked with jquery and mysql
本文介绍了复选框 - 选中或取消选中使用jQuery和MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前在做一个系统,它必须能够检查/取消选中的复选框。每次它改变了状态,我需要jQuery的制造和AJAX调用一个页面,该更新数据库。
I am currently doing a system where it has to be possible to check/uncheck a checkbox. Everytime it changes status I need jquery to make and ajax call to a page, that updates the database.
我的问题是 - 我怎么能做到这一点,于是更新
My problem is - how can I do this, so it updates?
在此先感谢。
推荐答案
例如,你可以做到这一点是这样的:
For example you can do it like this:
首先,你要看看,如果复选框被选中:
First you have to look if the checkbox is checked:
$("#yourSelector").live("click", function(){
var id = parseInt($(this).val(), 10);
if($(this).is(":checked")) {
// checkbox is checked -> do something
} else {
// checkbox is not checked -> do something different
}
});
您可以通过Ajax加载的具体内容:
You can load specific content via Ajax:
$.ajax({
type: "POST",
dataType: "xml",
url: "path/to/file.php",
data: "function=loadContent&id=" + id,
success: function(xml) {
// success function is called when data came back
// for example: get your content and display it on your site
}
});
这篇关于复选框 - 选中或取消选中使用jQuery和MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文