简体   繁体   English

仅当直接单击 object 时才发生单击事件

[英]click event only if the object is directly clicked

In the example below how to write console only if .bradio is clicked, and not button在下面的示例中,仅在单击.bradio而不是button时如何编写控制台
ie on button click bradio.eq(1) should be checked, but without console writing ie on button click bradio.eq(1)应该检查,但没有控制台写入

 $('.bradio').on('change', function(){ console.log('onchange'); }); $('button').on('click', function(){ $('.bradio').eq(1).click(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type='radio' class='bradio' name='bradio' value='pub' title='PUBLIC'> <input type='radio' class='bradio' name='bradio' value='priv' title='PRIVATE'> <br> <button>CLICK</button>

To select an element without manually creating a click event, set its checked property:为 select 一个元素而无需手动创建点击事件,设置其checked属性:

 $('.bradio').on('change', function() { console.log('onchange'); }); $('button').on('click', function() { $('.bradio').eq(1).prop('checked', true); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="radio" class="bradio" name="bradio" value="pub" title="PUBLIC"> <input type="radio" class="bradio" name="bradio" value="priv" title="PRIVATE"> <br> <button>CLICK</button>

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

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