简体   繁体   English

为一个复选框调用2个JavaScript函数

[英]Call 2 JavaScript functions for one checkbox

I've got a little problem, my checkbox already has an ID, Name etc. attached to it, so I don't know how to link the JavaScript code below to the checkbox, because the ID and Name are already used. 我有一个小问题,我的复选框已经附加了ID,名称等。因此,由于ID和名称已被使用,因此我不知道如何将下面的JavaScript代码链接到该复选框。 I already know that you cannot use multiple IDs, because it will then only use the first ID specified. 我已经知道您不能使用多个ID,因为它将仅使用指定的第一个ID。

Any ideas how to fix this? 任何想法如何解决这一问题?

 setTimeout(function(){ document.getElementById('checkboxdelay').checked = true; },1000) 
 <input name="product" value="199" type="checkbox" id="p4" id="checkboxdelay" onChange="totalIt()"/> 

You don't have to select one element in different ways to attach different javascript code, But if you want to call it in a different way you can always assign a class to it and identify element with javascript method: document.getElementsByClassName('classname') 您不必以不同的方式选择一个元素来附加不同的javascript代码,但是如果您想以不同的方式调用它,则可以始终为其分配一个类并使用javascript方法来标识元素:document.getElementsByClassName('classname “)

 setTimeout(function(){ document.getElementsByClassName('checkboxdelay')[0].checked = true; },1000) 
 <input name="product" value="199" type="checkbox" id="p4" class="checkboxdelay" onChange="totalIt()"/> 

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

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