js事件clik、event.ketcode == 13等多次触发解决方案

本文介绍了在JavaScript中如何处理重复触发事件的问题,并给出了具体的解决办法。通过使用.unbind()方法解除原有的事件绑定,再重新绑定新的事件处理函数,可以有效地避免事件被多次触发的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工作中碰到的第一次发现是下拉加载的时候,js会多次触发某个点击事件,第二次就是在做keydown中的event.keycode == 13

解决方法:

$('xxx').unbind('事件').事件(function(){});

例子:

$('#obj').unbind('keydown').keydown(function(event){});

$('#obj').unbind('on').on('click',function(){});

07-31 10:23:54.451004 6920 12272 D PTC.APPCORE.CoreService: request isAsync: false, binder: null 07-31 10:23:54.451012 6920 12272 D PTC.DISC.DiscoveryRequestDispatcher: -- service dispatcher -- dispatch request with method(stopDiscovery) 07-31 10:23:54.451065 6920 12272 I PTC.CONN.ConnectionCoordinator: -- ACCEPT CONNECTION -- removeWakeupOptions: AgentClient(agentId=37175051, channelName=, appName=, pkg=com.heytap.accessory, pid=24286, role=ACCEPTED, connectionId=0) 07-31 10:23:54.451087 6920 12272 D PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- stopDiscovery: cliK=com.heytap.accessory:24286:37175051 07-31 10:23:54.451096 6920 22271 D PTC.CONN.ConnectionCoordinator: -- ACCEPT CONNECTION -- response of accept: agentId()-isSuccess(false) null null 07-31 10:23:54.451113 6920 12272 D PTC.DISC.DeviceDiscovery: Stop device discovery, client=DiscoveryClient(id=37175051, pkg=com.heytap.accessory, pid=24286) 07-31 10:23:54.451138 6920 12272 I PTC.DISC.LanDiscover: stopDiscovery, client=DiscoveryClient(id=37175051, pkg=com.heytap.accessory, pid=24286) 07-31 10:23:54.451148 6920 12272 I PTC.DISC.DiscoverContainer: Stop discovery, remove discovering client=DiscoveryClient(id=37175051, pkg=com.heytap.accessory, pid=24286), successCount=1, failureCount=0 07-31 10:23:54.451154 6920 12272 D PTC.DOMAIN.PTC.ConnResults onSuccess: it: kotlin.Unit 07-31 10:23:54.451168 6920 22271 D PTC.CONN.ScpConnectEventStatistics: end endScpConnectEvent: ScpConnectEvent,connectRole=1, keyType=BOTH, connectType=8, currentDevCategory=8, targetDevCategory=11, activeMode=0, connectResult=0, connectStartTime=1753928633071, connectFailReason=, connectEndTime=0, connectScpCost=0, connectTransportCost=0, connectFullCost=0, scpStage=, key = E64A1C11F47Bserver 07-31 10:23:54.451186 6920 22271 D PTC.CONN.ScpConnectEventStatistics: end endScpConnectEvent: error code: 2000 07-31 10:23:54.451198 6920 22271 D PTC.CONN.ScpConnectEventStatistics: handleScpConnectResult scpConnect result is: 0 07-31 10:23:54.451437 6920 22269 W PTC.CONN.InterconnectServiceSmartNetworking: -- interconnect networking -- o0 was cancelled 07-31 10:23:54.451503 24286 24445 I PTC.SERVICE.IosShareDiscovery: -- SHARE-DISC -- stopDiscovery serviceID=tap_share_ios result=true 07-31 10:23:54.451604 6920 22270 D PTC.DISC.IosHostApduService: -- NFC-DISC -- enableIosNfcDiscovery: false 07-31 10:23:54.451634 6920 22274 W PTC.CONN.InterconnectServiceSmartNetworking: -- interconnect networking -- o0 was cancelled 07-31 10:23:54.451708 6920 22269 D PTC.CONN.InterconnectServiceSmartNetworking: -- interconnect networking -- closeInternal (code:0, reason:) 07-31 10:23:54.451758 6920 22269 D PTC.CONN.InsecureSppConnector: call close. 07-31 10:23:54.451781 6920 22269 D PTC.CONN.FastInsecureSppServer: -- InsecureSppConnector Server -- outside call stopServer 07-31 10:23:54.451787 6920 22269 D PTC.CONN.FastInsecureSppServer: -- InsecureSppConnector Server -- closeServerSocket 07-31 10:23:54.451831 6920 22269 D PTC.CONN.ConnectionCoordinator: -- ACCEPT CONNECTION -- response of accept: agentId()-isSuccess(false) null null 07-31 10:23:54.451889 6920 22269 D PTC.CONN.ScpConnectEventStatistics: end endScpConnectEvent: ScpConnectEvent,connectRole=1, keyType=BOTH, connectType=8, currentDevCategory=8, targetDevCategory=11, activeMode=0, connectResult=1, connectStartTime=1753928633071, connectFailReason=, connectEndTime=0, connectScpCost=0, connectTransportCost=0, connectFullCost=0, scpStage=, key = E64A1C11F47Bserver 07-31 10:23:54.451894 6920 22269 D PTC.CONN.ScpConnectEventStatistics: end endScpConnectEvent: error code: 0 07-31 10:23:54.451897 6920 22269 D PTC.CONN.ScpConnectEventStatistics: handleScpConnectResult scpConnect result is: 1 07-31 10:23:54.451902 6920 22269 D PTC.CONN.ScpConnectEventStatistics: scpConnect result is: 1 07-31 10:23:54.451904 6920 22269 D PTC.CONN.ScpConnectEventStatistics: end endScpConnectEvent: error is 0 07-31 10:23:54.451918 6920 22269 I PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- on accept connection. key: com.heytap.accessory:accept-tap_share(wakeup) 07-31 10:23:54.451933 6920 22269 D PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- accept connection times(0) 07-31 10:23:54.451942 6920 22269 D PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- service advertising: start to listen the accept scp connection event with client 07-31 10:23:54.452028 6920 22269 D PTC.CONN.ScpConnectEventStatistics: start upload scpConnectEvent = ScpConnectEvent,connectRole=1, keyType=BOTH, connectType=8, currentDevCategory=8, targetDevCategory=11, activeMode=0, connectResult=0, connectStartTime=1753928634452, connectFailReason=, connectEndTime=0, connectScpCost=0, connectTransportCost=0, connectFullCost=0, scpStage=, key is=E64A1C11F47Bserver 07-31 10:23:54.452601 4622 4622 I SystemUi--Statusbar: PhoneStatusBarPolicy-->updateLocationFromController isLocationActive:false 07-31 10:23:54.452697 6593 6613 W LOG_FLOWCTRL: ==LOGS OVER PROC QUOTA(300), rows(234) bytes(16771) com.android.nfc u(0) l(0) t(0) c(0) DROPPED== 07-31 10:23:54.452697 6593 6613 D VendorNfcService: enableNfcShareMode, enable == false 07-31 10:23:54.453099 6920 22271 D PTC.CONN.ScpConnectEventStatistics: scpConnect result is: 1 07-31 10:23:54.453138 6920 22271 D PTC.CONN.ScpConnectEventStatistics: end endScpConnectEvent: error is 0 07-31 10:23:54.453154 6920 22271 I PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- on accept connection. key: com.heytap.accessory:24286:253565444 07-31 10:23:54.453168 6920 22271 D PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- accept connection times(0) 07-31 10:23:54.453188 6920 22271 I PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- service advertising: stop listening the accept scp connection event with client,connectionId:748046045 07-31 10:23:54.453253 6920 22269 D PTC.DISC.DiscoveryRequestServerImpl: -- service dispatcher -- onRequestStarted connectId:1716302511 07-31 10:23:54.453266 6920 22271 D PTC.CONN.R8$$SyntheticClass: cancel scp. connectId: 748046045 07-31 10:23:54.453275 6920 22269 D PTC.CONN.InterconnectServiceSmartNetworking: -- interconnect networking -- acceptInternal 07-31 10:23:54.453290 6920 22271 D PTC.CONN.R8$$SyntheticClass: cancel scp: 748046045 not found 07-31 10:23:54.453528 6920 22269 W PTC.CONN.BluetoothConnector: Bluetooth is unable, please check! 07-31 10:23:54.454138 5252 5372 V AppProvider_query: com.heytap.accessory getSecureSetting(key_settings_strengthen_service_oaf, 10105) 07-31 10:23:54.454609 6920 22269 I SettingImpl: domestic quick device toggle value is 1 07-31 10:23:54.455102 5252 5372 V AppProvider_query: com.heytap.accessory getSecureSetting(key_settings_strengthen_service_oaf, 10105) 07-31 10:23:54.455543 6920 22269 I SettingImpl: domestic quick device toggle value is 1 07-31 10:23:54.455600 6920 22269 D PTC.CONN.InsecureSppConnector: call acceptConnection: EE15 07-31 10:23:54.455613 6920 22269 D PTC.CONN.FastInsecureSppServer: -- InsecureSppConnector Server -- acceptConnection serviceInfo: tap_share, com.heytap.accessory 07-31 10:23:54.455896 6920 22271 D PTC.NFC.ScpManager: -- SCP -- registerScpProcessor: agentAddress=****866B 07-31 10:23:54.457229 6593 6613 I TapToShareEvent: no setConfig before, set rf to default 07-31 10:23:54.457399 6593 6613 D NfcUpdateConfigUtil: Updating configuration in file keyPara: default 07-31 10:23:54.457531 6593 6613 D NfcUpdateConfigUtil: Updating configuration in file configUpdateFile: /data/vendor/nfc/libnfc_default_config.conf 07-31 10:23:54.457960 4622 4622 D RowAnimatorExtImpl: init:tx,view:StatusBarIconView(slot='logging' alpha=0.0 icon=StatusBarIcon(icon=Icon(typ=RESOURCE pkg=com.android.systemui id=0x7f08190e) visible user=0 ) visibleState=ICON iconColor=#0 staticDrawableColor=#0 decorColor=#ccffffff animationStartColor=#0 currentSetColor=#0 notification=null),translationX: -56.0 0.0 07-31 10:23:54.458679 4622 4622 D SystemUi--Statusbar: StatBatteryMeterView-->onHiddenChanged false, false disable=false, lastShowStyle=1 07-31 10:23:54.458224 6593 6593 E NxpNfcService: Setting configs for Transit 07-31 10:23:54.458762 4622 4622 D SystemUi--Statusbar: StatBatteryMeterView-->onHiddenChanged showStyle:1. 高通日志解释
最新发布
08-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值