当前位置: 首页 > 面试题库 >

如何修复AJAX复选框时始终触发?

濮阳鸿祯
2023-03-14
问题内容

有时候,这种AJAX会触发,有时却不会,我来解释一下。

habit.js

$(document).ready(function()
{
  $(".habit-check").change(function()
  {
    habit = $(this).parent().siblings(".habit-id").first().attr("id");
    level = $(this).siblings(".level-id").first().attr("id");
    if($(this).is(":checked"))
    {
       $.ajax(
       {
         url: "/habits/" + habit + "/levels/" + level + "/days_missed",
         method: "POST"
       });
    }
    else
    {
       $.ajax(
       {
         url: "/habits/" + habit + "/levels/" + level + "/days_missed/1",
         method: "DELETE"
       });
    }
  });
});

仅在加载显示页面并刷新它之后才会触发,以便终端看起来像这样:

Started GET "/habits/1" for ::1 at 2015-06-20 23:55:42 -0400
Processing by HabitsController#show as HTML
  Parameters: {"id"=>"1"}
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  Habit Load (0.1ms)  SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('ingrain'))
  CACHE (0.0ms)  SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  Level Load (0.2ms)  SELECT "levels".* FROM "levels" WHERE "levels"."habit_id" = ?  [["habit_id", 1]]
  ActsAsTaggableOn::Tag Load (0.3ms)  SELECT  DISTINCT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."tagger_id" = ? AND "taggings"."tagger_type" = ?  ORDER BY taggings_count desc LIMIT 20  [["tagger_id", 1], ["tagger_type", "User"]]
   (0.1ms)  SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  Habit Load (0.1ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."id" = ? LIMIT 1  [["id", 1]]
  CACHE (0.0ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."id" = ? LIMIT 1  [["id", "1"]]
  Habit Load (0.1ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."user_id" = ? AND "habits"."id" = ? LIMIT 1  [["user_id", 1], ["id", 1]]
  CACHE (0.0ms)  SELECT "levels".* FROM "levels" WHERE "levels"."habit_id" = ?  [["habit_id", 1]]
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'tags') GROUP BY tags.id  [["taggable_id", 1], ["taggable_type", "Habit"]]
  Note Load (0.1ms)  SELECT "notes".* FROM "notes" WHERE "notes"."habit_id" = ?  ORDER BY notes_date  [["habit_id", 1]]
  Rendered notes/_notes.html.erb (2.0ms)
  Rendered notes/_form.html.erb (3.9ms)
  User Load (0.1ms)  SELECT "users".* FROM "users" INNER JOIN "habit_likes" ON "users"."id" = "habit_likes"."user_id" WHERE "habit_likes"."habit_id" = ?  [["habit_id", 1]]
  Comment Load (0.1ms)  SELECT "comments".* FROM "comments" WHERE "comments"."habit_id" = ?  [["habit_id", 1]]
  Rendered comments/_comments.html.erb (0.8ms)
  Rendered comments/_form.html.erb (1.0ms)
  Rendered habits/show.html.erb within layouts/application (24.0ms)
   (0.2ms)  SELECT COUNT(*) FROM "notifications" WHERE "notifications"."user_id" = ?  [["user_id", 1]]
  Rendered layouts/_header.html.erb (2.9ms)
   (0.1ms)  SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ? AND 1=0  [["user_id", 1]]
  Rendered habits/_today.html.erb (1.0ms)
  Goal Load (0.2ms)  SELECT  "goals".* FROM "goals" WHERE "goals"."user_id" = ? AND "goals"."accomplished" = 'f'  ORDER BY deadline LIMIT 3  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."followed_id" WHERE "relationships"."follower_id" = ?  [["follower_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "goals" WHERE "goals"."user_id" = ? AND "goals"."accomplished" = 'f'  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "quantifieds" WHERE "quantifieds"."user_id" = ?  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."follower_id" WHERE "relationships"."followed_id" = ?  [["followed_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "goals" WHERE "goals"."user_id" = ? AND "goals"."accomplished" = 't'  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "results" INNER JOIN "quantifieds" ON "results"."quantified_id" = "quantifieds"."id" WHERE "quantifieds"."user_id" = ? AND "results"."bad" = 'f'  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "valuations" WHERE "valuations"."user_id" = ?  [["user_id", 1]]
  Rendered layouts/_count.html.erb (10.7ms)
  Rendered layouts/_tags.html.erb (0.1ms)
  Rendered layouts/_recommendations.html.erb (0.0ms)
  Quantified Load (0.1ms)  SELECT "quantifieds".* FROM "quantifieds" WHERE "quantifieds"."user_id" = ? AND "quantifieds"."categories" = ?  [["user_id", 1], ["categories", "Averaged"]]
  Quantified Load (0.1ms)  SELECT "quantifieds".* FROM "quantifieds" WHERE "quantifieds"."user_id" = ? AND "quantifieds"."categories" = ?  [["user_id", 1], ["categories", "Instance"]]
   (0.1ms)  SELECT COUNT(*) FROM "valuations" WHERE "valuations"."user_id" = ? AND (1 = 0)  [["user_id", 1]]
  Rendered layouts/_value.html.erb (0.8ms)
  Rendered layouts/_sidebar.html.erb (18.9ms)
Completed 200 OK in 324ms (Views: 307.4ms | ActiveRecord: 3.3ms)


Started GET "/assets/application-2b528cffd402884831208f505b651927.css?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/jquery-ea2706bc2d0586731b7c00ec2cd0a414.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/stylesheet-3e834b3a950daa6165191fa42b13a968.css?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/jquery_ujs-29277b946c1d3754af13672bfec0c660.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/bootstrap-d16805677947f8c7ce91cea7ae7f82b0.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/cocoon-07a2b3765fb91baf2df1cea98d97eed0.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/turbolinks-3a7cdb8630f3e86770867bd488a098e0.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/account_activations-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/comments-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/days_missed-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/facebook-faaf7b74474e5a746a0c4a160e4705d2.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/habit-ff66f57b87d00b4469848f1af3f6910a.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/habits-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/activities-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/pages-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/password_resets-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/notes-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/quantified-5cae96afee8ab50e506c00828f3042b3.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/goals-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/quantifieds-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/relationships-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/sessions-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/notifications-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/tags-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/users-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/values-8f6eecd1178ef85964369ec66d33c4f1.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/application-6fd7d78d93af9f6901c08c3bc66303d0.js?body=1" for ::1 at 2015-06-20 23:55:42 -0400


Started GET "/assets/bootstrap/glyphicons-halflings-regular-195cb410b49d75c104a5bc6ad385ac77.woff" for ::1 at 2015-06-20 23:55:43 -0400

仅加载显示页面一次将无法完成工作,因为选中标记不会触发AJAX(请注意上面的所有GET和下面的GET缺少,我认为这与涡轮链接有关)。

Started GET "/habits/1" for ::1 at 2015-06-21 00:09:02 -0400
Processing by HabitsController#show as HTML
  Parameters: {"id"=>"1"}
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  Habit Load (0.1ms)  SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('ingrain'))
  CACHE (0.0ms)  SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  Level Load (0.2ms)  SELECT "levels".* FROM "levels" WHERE "levels"."habit_id" = ?  [["habit_id", 1]]
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT  DISTINCT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."tagger_id" = ? AND "taggings"."tagger_type" = ?  ORDER BY taggings_count desc LIMIT 20  [["tagger_id", 1], ["tagger_type", "User"]]
   (0.1ms)  SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  Habit Load (0.1ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."id" = ? LIMIT 1  [["id", 1]]
  CACHE (0.0ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."id" = ? LIMIT 1  [["id", "1"]]
  Habit Load (0.1ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."user_id" = ? AND "habits"."id" = ? LIMIT 1  [["user_id", 1], ["id", 1]]
  CACHE (0.0ms)  SELECT "levels".* FROM "levels" WHERE "levels"."habit_id" = ?  [["habit_id", 1]]
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'tags') GROUP BY tags.id  [["taggable_id", 1], ["taggable_type", "Habit"]]
  Note Load (0.1ms)  SELECT "notes".* FROM "notes" WHERE "notes"."habit_id" = ?  ORDER BY notes_date  [["habit_id", 1]]
  Rendered notes/_notes.html.erb (1.1ms)
  Rendered notes/_form.html.erb (3.2ms)
  User Load (0.1ms)  SELECT "users".* FROM "users" INNER JOIN "habit_likes" ON "users"."id" = "habit_likes"."user_id" WHERE "habit_likes"."habit_id" = ?  [["habit_id", 1]]
  Comment Load (0.1ms)  SELECT "comments".* FROM "comments" WHERE "comments"."habit_id" = ?  [["habit_id", 1]]
  Rendered comments/_comments.html.erb (0.9ms)
  Rendered comments/_form.html.erb (1.1ms)
  Rendered habits/show.html.erb within layouts/application (21.4ms)
   (0.1ms)  SELECT COUNT(*) FROM "notifications" WHERE "notifications"."user_id" = ?  [["user_id", 1]]
  Rendered layouts/_header.html.erb (2.3ms)
   (0.1ms)  SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ? AND 1=0  [["user_id", 1]]
  Rendered habits/_today.html.erb (0.9ms)
  Goal Load (0.2ms)  SELECT  "goals".* FROM "goals" WHERE "goals"."user_id" = ? AND "goals"."accomplished" = 'f'  ORDER BY deadline LIMIT 3  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."followed_id" WHERE "relationships"."follower_id" = ?  [["follower_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "goals" WHERE "goals"."user_id" = ? AND "goals"."accomplished" = 'f'  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "quantifieds" WHERE "quantifieds"."user_id" = ?  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."follower_id" WHERE "relationships"."followed_id" = ?  [["followed_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "goals" WHERE "goals"."user_id" = ? AND "goals"."accomplished" = 't'  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "results" INNER JOIN "quantifieds" ON "results"."quantified_id" = "quantifieds"."id" WHERE "quantifieds"."user_id" = ? AND "results"."bad" = 'f'  [["user_id", 1]]
   (0.1ms)  SELECT COUNT(*) FROM "valuations" WHERE "valuations"."user_id" = ?  [["user_id", 1]]
  Rendered layouts/_count.html.erb (9.3ms)
  Rendered layouts/_tags.html.erb (0.0ms)
  Rendered layouts/_recommendations.html.erb (0.1ms)
  Quantified Load (0.1ms)  SELECT "quantifieds".* FROM "quantifieds" WHERE "quantifieds"."user_id" = ? AND "quantifieds"."categories" = ?  [["user_id", 1], ["categories", "Averaged"]]
  Quantified Load (0.1ms)  SELECT "quantifieds".* FROM "quantifieds" WHERE "quantifieds"."user_id" = ? AND "quantifieds"."categories" = ?  [["user_id", 1], ["categories", "Instance"]]
   (0.1ms)  SELECT COUNT(*) FROM "valuations" WHERE "valuations"."user_id" = ? AND (1 = 0)  [["user_id", 1]]
  Rendered layouts/_value.html.erb (0.8ms)
  Rendered layouts/_sidebar.html.erb (17.6ms)
Completed 200 OK in 318ms (Views: 301.9ms | ActiveRecord: 3.1ms)

显示页面 称为AJAX

<div class="strikes">
  <% if @habit.current_level_strike %> 
    <div class="btn" id="red"> <label id="<%= @habit.id %>" class="habit-id">Strikes:</label>
  <% else %> 
    <div class="btn" id="gold"> <label id="<%= @habit.id %>" class="habit-id-two">Strikes:</label>
  <% end %>
    <% @habit.levels.each_with_index do |level, index| %>
      <% if @habit.current_level >= (index + 1) %>
        <p>
          <% if @habit.current_level_strike %> 
            <label id="<%= level.id %>" class="level-id">Level <%= index + 1 %>:</label> 
          <% else %> 
            <label id="<%= level.id %>" class="level-id-two">Level <%= index + 1 %>:</label> 
          <% end %>
          <%= check_box_tag nil, true, level.missed_days > 0, {class: "habit-check"} %>
          <%= check_box_tag nil, true, level.missed_days > 1, {class: "habit-check"} %>
          <%= check_box_tag nil, true, level.missed_days > 2, {class: "habit-check"} %>
       </p>
      <% end %>
    <% end %>
  </div>
</div>

这就是AJAX触发的 代码days_missed_controller.rb

class DaysMissedController < ApplicationController
  before_action :logged_in_user, only: [:create, :destroy]

  def create
    habit = Habit.find(params[:habit_id])
    habit.missed_days = habit.missed_days + 1
    @habit.save!
    level = habit.levels.find(params[:level_id])
    level.missed_days = level.missed_days + 1
    if level.missed_days == 3
      level.missed_days = 0
      level.days_lost += habit.calculate_days_lost + 1
    end
    level.save!
    head :ok # this returns an empty response with a 200 success status code
  end

  def destroy
    habit = Habit.find(params[:habit_id])
    habit.missed_days = habit.missed_days - 1
    habit.save!
    level = habit.levels.find(params[:level_id])
    level.missed_days = level.missed_days - 1
    level.save!
    head :ok # this returns an empty response with a 200 success status code
  end
end

这是 要点
。抱歉,我是AJAX的新手,并获得了帮助,因此我的描述水平可能很基本。请不要犹豫,要求进一步的澄清或代码:-]

更新

因此,换句话说,如果用户加载了显示页面,然后选中了复选框,则没有任何内容发送到服务器;如果用户加载显示页面然后刷新它,然后选中服务器中进行此POST的复选框:

Started POST "/habits/1/levels/1/days_missed" for 127.0.0.1 at 2015-06-22 02:15:21 -0400
Processing by DaysMissedController#create as */*
  Parameters: {"habit_id"=>"1", "level_id"=>"1"}
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  Habit Load (0.2ms)  SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  ActsAsTaggableOn::Tag Load (0.3ms)  SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('ingrain'))
  CACHE (0.0ms)  SELECT "habits".* FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  Level Load (0.2ms)  SELECT "levels".* FROM "levels" WHERE "levels"."habit_id" = ?  [["habit_id", 1]]
  ActsAsTaggableOn::Tag Load (0.3ms)  SELECT  DISTINCT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."tagger_id" = ? AND "taggings"."tagger_type" = ?  ORDER BY taggings_count desc LIMIT 20  [["tagger_id", 1], ["tagger_type", "User"]]
   (0.1ms)  SELECT COUNT(*) FROM "habits" WHERE "habits"."user_id" = ?  [["user_id", 1]]
  Habit Load (0.1ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."user_id" = ? AND "habits"."id" = ? LIMIT 1  [["user_id", 1], ["id", 1]]
  Habit Load (0.1ms)  SELECT  "habits".* FROM "habits" WHERE "habits"."id" = ? LIMIT 1  [["id", 1]]
   (0.1ms)  begin transaction
  CACHE (0.0ms)  SELECT "levels".* FROM "levels" WHERE "levels"."habit_id" = ?  [["habit_id", 1]]
  CACHE (0.0ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  ActsAsTaggableOn::Tag Load (0.2ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)  [["taggable_id", 1], ["taggable_type", "Habit"]]
  CACHE (0.0ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)  [["taggable_id", 1], ["taggable_type", "Habit"]]
  ActsAsTaggableOn::Tag Load (0.1ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = ? AND "taggings"."taggable_type" = ? AND (taggings.context = 'tags' AND
                                    taggings.tagger_id = 1 AND
                                    taggings.tagger_type = 'User')  [["taggable_id", 1], ["taggable_type", "Habit"]]
   (0.1ms)  commit transaction
  Level Load (0.2ms)  SELECT  "levels".* FROM "levels" WHERE "levels"."habit_id" = ? AND "levels"."id" = ? LIMIT 1  [["habit_id", 1], ["id", 1]]
   (0.1ms)  begin transaction
  SQL (0.3ms)  UPDATE "levels" SET "missed_days" = ?, "updated_at" = ? WHERE "levels"."id" = ?  [["missed_days", 1], ["updated_at", "2015-06-22 06:15:21.959609"], ["id", 1]]
   (2.8ms)  commit transaction
Completed 200 OK in 40ms (ActiveRecord: 5.4ms)

问题答案:

这可能是Turbolinks的问题,您是否可以尝试更改javascript:

$(document).ready(function()
{
  // ...
}

看起来像:

$(document).on("ready page:load", function() {
  // ..
}

请让我知道是否有帮助!

祝好运!



 类似资料:
  • 我的JavaFx FXML应用程序有问题。 当我在表单上选中复选框时,我想根据单击的复选框执行一个方法。是否有任何方法可以将复选框的名称传递给该方法,以便对其执行一些有条件的工作? 我有两个复选框,只能选择一个。当我单击其中一个时,应取消选择另一个,反之亦然。显然,下面的代码将无法工作,因此我希望传递被单击对象的名称。 任何帮助都将不胜感激,非常感谢。

  • 如果我打开活动,复选框始终保持选中状态,即使我取消选中它并离开活动或关闭应用程序,在重新启动活动后,它也将保持选中状态。 我已尝试使用以下代码段保存活动的状态。 复选框应始终处于用户离开它的状态(选中或未选中)。

  • 这是我的模板名为admin的代码。html: 如前所述,我得到了10个函数,这些函数可以读取多个。csv报告并将数据上传到模型中,我使用URL部分触发它们。在我看来。py我将展示两个示例:

  • 问题内容: 这是困扰我的CSS小问题之一。Stack Overflow周围的人们如何垂直对齐 以及他们 始终如一的 跨浏览器 ?每当我在Safari中正确对齐它们(通常在上使用)时,它们在Firefox和IE中就完全关闭了。在Firefox中进行修复,不可避免地将Safari和IE弄乱了。每次编写表单时,我都会在此上浪费时间。 这是我使用的标准代码: 我通常使用Eric Meyer的重置,因此表单

  • 我试图创建一个表单,该表单顶部有一个复选框,当用户选中该复选框时,它会选择其他特定的复选框,但不是所有复选框。我很难通过反复试验或搜索找到答案。我唯一能找到的就是“全选”选项。不是我想要的。 理想情况下,当用户选中“管理包”旁边的复选框时,我想要“Chrome外观组”和“远程启动” 下面是代码和我在这方面的基本尝试,但它不起作用。提前谢谢。 超文本标记语言: Javascript 我不知道这个Ja

  • 这会找到我想要的节点吗?如果没有,我如何获得节点并正确地更改属性? 谢谢。马格努斯