jQuery - 在按钮之间切换

时间:2016-04-22 22:39:45

标签: javascript jquery html css

我的菜单中有两个public function acceptedChallenges($user_one_id, $user_two_id) { $stmt = $this->conn->prepare("SELECT u.name, c.user_one_id, c.user_two_id, c.status, c.created_at, c.isRead, c.id FROM users u, challenges c WHERE c.user_one_id = ? AND c.user_two_id = ? AND c.status = 1 AND (u.id = c.user_one_id OR u.id = c.user_two_id)"); $stmt->bind_param("ii", $user_one_id, $user_two_id); if ($stmt->execute()) { $request = $stmt->get_result(); $stmt->close(); return $request; } else { return NULL; } } 元素。我想要实现的是在单击它们时在类之间切换。如果我点击第一个,它应该得到$app->post('/accepted_challenges', 'authenticate', function() use ($app) { verifyRequiredParams(array('user_one_id', 'user_two_id')); $response = array(); $db = new DbHandler(); $user_one_id = $app->request->post('user_one_id'); $user_two_id = $app->request->post('user_two_id'); $requests = $db->acceptedChallenges($user_one_id, $user_two_id); if ($requests != NULL) { $response["error"] = false; $response["requests"] = array(); while ($request = $requests->fetch_assoc()) { $tmp = array(); $tmp["name"] = $request["name"]; $tmp["id"] = $request["id"]; $tmp["user_one_id"] = $request["user_one_id"]; $tmp["user_two_id"] = $request["user_two_id"]; $tmp["created_at"] = $request["created_at"]; $tmp["isRead"] = $request["isRead"]; array_push($response["requests"], $tmp); } } else { $response["error"] = true; $response["message"] = "No pending requests."; } echoRespnse(200, $response); }); 类,另一个得到<li>类。

到目前为止我的代码无法正常工作,我找不到办法。

fiddle here:

.activeBtn

1 个答案:

答案 0 :(得分:1)

解决了我不知道removeClass

 $(".menuBtns").click(function() {
      // remove classes from all
      $(".menuBtns").removeClass("activeBtn");
      // add class to the one we clicked
      $(this).addClass("activeBtn");    });