简体   繁体   English

单击时选中标记没有响应

[英]Checkmark not responding when clicked

i have the following link that when you click on it,it changes my checkmark colour. 我有以下链接,当您单击它时,它会更改我的选中标记颜色。 as follows 如下

 .checkmark { display: inline-block; width: 22px; /* height: 22px; */ height: 17px; -ms-transform: rotate(45deg); -webkit-transform: rotate(45deg); transform: rotate(45deg); margin-left: 50%; margin-bottom: 1px; } .checkmark:before { content: ''; position: absolute; width: 3px; height: 9px; background-color: #ccc; left: 11px; top: 6px; } .checkmark { cursor: pointer; } .checkmark:after { content: ''; position: absolute; width: 3px; height: 3px; background-color: #ccc; left: 8px; top: 12px; } input[type="checkbox"]:checked+.checkmark:before, input[type="checkbox"]:checked+.checkmark:after { background-color: blue; } 
 <label dataid="' + this.MarketID + '"><input type= "checkbox" style= "display:none;" id="cb' + this.MarketID + '" >Click Me<span for="cb' + this.MarketID + '" class="checkmark"></span ></label > 

the problem i am having is that when i add an onclick function to my label the checkmark stops resonding as follows: 我遇到的问题是,当我在标签上添加onclick函数时,复选标记停止响应,如下所示:

 function followInternalink(event) { var link = $(event.target).closest('label'); var destination = link.attr('data-destination'); if ((destination == 'null' || destination == 'local') && link.attr('dataid')) { event.preventDefault(); var id = link.attr('dataid'); navigateToEvent(id); } else { //does something else } } 
 .checkmark { display: inline-block; width: 22px; /* height: 22px; */ height: 17px; -ms-transform: rotate(45deg); -webkit-transform: rotate(45deg); transform: rotate(45deg); margin-left: 50%; margin-bottom: 1px; } .checkmark:before { content: ''; position: absolute; width: 3px; height: 9px; background-color: #ccc; left: 11px; top: 6px; } .checkmark { cursor: pointer; } .checkmark:after { content: ''; position: absolute; width: 3px; height: 3px; background-color: #ccc; left: 8px; top: 12px; } input[type="checkbox"]:checked+.checkmark:before, input[type="checkbox"]:checked+.checkmark:after { background-color: blue; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <label onclick="followInternalink(event)" data-destination="local" dataid="' + this.MarketID + '" ><input type= "checkbox" style= "display:none;" id="cb' + this.MarketID + '" >Click Me<span for="cb' + this.MarketID + '" class="checkmark"></span ></label > 

the above function works as i want it to,it just stops checking the checkmark, what am i doing wrong? 上面的功能按我想要的方式工作,它只是停止检查选中标记,我在做什么错?

You are setting event.preventDefault(); 您正在设置event.preventDefault(); which may be the reason you native HTML behaviour stopped working 这可能是您本机HTML行为停止工作的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM