取消选中复选框时未检测到功能

时间:2018-01-29 13:06:21

标签: jquery checkbox

我有一个复选框,如果我检查它,重定向到另一个函数,如下面的代码所示:

function Allchecks1(event) {
            event.stopPropagation();
            var market = $(event.target).closest('a');
            var destination = market.attr('data-destination');
            if ((destination == 'null' || destination == 'local') && market.attr('dataid')) {
                var id = market.attr('dataid');
                navigateToEvent(id); // Passes the ID to this function
                return true;   
            }
            else if (!$('#cb').is(':checked')) {
                alert("owiedjiej");     // Did a test when I uncheck the textbox; nothing happened
            }  
        }

function navigateToEvent(id) {
            var url = '/' + 'List/events/';
            if (id)
                url += id;
        }

上面的代码将ID传递给函数navigateToEvent(),因此输出例如如下:

/List/events/1111

我想要实现的是,当我取消选中该复选框时,应该删除ID并且我的预期输出应为:

/List/events/

我如何实现这一目标?我添加了一个警告,仅用于测试复选框的注释,它不会触发任何警报。

HTML:

<li "><a  data-destination="local" dataid="' + this.MarketID + '" data-nodeid = "' + this.NodeId + '" ><span><input type="checkbox" id="cb" onclick=Allchecks1(event);></span></a></li>');

2 个答案:

答案 0 :(得分:0)

尝试这种方法,以便您可以轻松跟踪复选框的点击。

ret = ftruncate (fd, sizeof (size));

答案 1 :(得分:0)

在解雇代码的最多时刻,它会在触发后进行检查,然后将取消选中,因此请更改您的代码

require 'observer'

# Trying to undef Observable's #changed and #changed?
# But really, when included, it also undefs methods from
# other modules included by original class
module TryingToRewriteChanged
  include ::Observable

  alias triggerable_changed? changed?
  alias triggerable_changed changed

  undef_method :changed?
  undef_method :changed
end

# Custom module which has some logic in .included
module Triggerable
  def self.included(obj)
    obj.class_eval do
      include TryingToRewriteChanged
      # ... And other magic
    end
  end
end

# Mock for some ActiveRecord module with 
# #changed and #changed? definitions
module ActiveRecord
  module SomeActiveRecordModule
    def changed
      puts 'original changed'
    end

    def changed?
      puts 'original changed?'
    end
  end
end

# Mock for ActiveRecord::Base class
module ActiveRecord
  class Base
    include SomeActiveRecordModule
  end
end

# Example model, which need to include Triggerable module
class SomeModel < ActiveRecord::Base
  include Triggerable
end

# ActiveRecord's #changed is no more available
SomeModel.new.changed
# -> undefined method `changed'