2

我有几个复选框,如下所示。当检查一个复选框时,必须从mySQL加载结果,并且在未选中的重新选中时,必须加载结果,而无需页面刷新。

几乎与http://www.facebook.com/find-friends/browser/相同

我能怎么做?

 <div class="tags">  <label><input type="checkbox" class="arts" /> Arts </label> <label><input type="checkbox" class="computers" /> Computers </label> <label><input type="checkbox" class="health" /> Health </label> <label><input type="checkbox" class="video-games" /> Video Games </label> </div>
4

4 回答 4

0

You can get the value of checked checkbox $(‘[name=”hobbies”:checked]’).val() and for unchecked box you can use $("input:checkbox:not(:checked)")

于 2014-01-02T15:22:15.037 回答
0

您可以使用 JavaScript 执行此操作,并使用 jQuery 看这里:http ://api.jquery.com/jQuery.get/

于 2012-05-16T16:12:04.243 回答
0

使用 jQuery(如上所述)最容易做到这一点。一般来说,你会经历一系列的“找东西”然后“做某事”的任务。我不是 javascript 专家,但我在逻辑上的微弱尝试应该能让你走上正确的道路。

jQuery 逻辑看起来像这样:

希望这可以帮助。

于 2012-05-16T16:35:57.943 回答
0

您需要使用 Ajax。

正如人们所建议的那样,jQuery 允许您轻松地做到这一点。

例子:

在 JavaScript 文件中:

$.ajax({
  url: '/get-data',
  type: 'GET',
  data: { tags: anArrayOfCheckedCheckboxes }, // get the checked checkboxes the way you want
  complete: function(response) {
    // do what do you need with the response (display results for example)
  }
});

在 PHP 方面(/get-data URL):

$tags = $_GET['tags'];
// get the results from the database
return json_encode($results);
于 2012-05-16T16:51:03.467 回答