div标签的javascript onclick事件 [英] javascript onclick event for div tag
本文介绍了div标签的javascript onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have the following div tag: (jobform)
<!--jobform-->
<div class="jobform" onclick="SetChecks();">
<div class="jobform_l" ><?php _e('Category');?> : <span class="required">*</span> </div>
<div class="jobform_r" >
<?php require_once (TEMPLATEPATH . '/jobs_category.php');?>
</div>
<div class="aglabel">Job Poster :</div>
</div><!--jobform-->
我正在生成一组复选框(类别),因为我没有复选框标签,因此我需要捕获此div上的onclick事件并选中/取消选中某些复选框.就像当一个被选中时,我希望另一个未被选中.因此,我已经实现了以下javascript来做到这一点:
I am generating an array of checkboxes (Categories), since I dont have the checkbox tags I will need to capture the event of onclick on this div and check/uncheck certain checkboxes. Like when one is checked I want the other one to be unchecked. So I have implemented the following javascript to do that:
<script type="text/javascript">
function SetChecks() {
Alert("test");
if(document.getElementById('category_41').checked)
{
document.getElementById('category_39').checked = false;
}
else if(document.getElementById('category_39').checked)
{
document.getElementById('category_41').checked = false;
}
</script>
但是由于某种原因,它没有被触发,因此我尝试放置Alert()
只是为了确保它被单击或否.
But for some reason it is not being triggered, I event tried putting an Alert()
just to make sure it is being clicked or no. And it is not.
推荐答案
JavaScript区分大小写,因此即使触发了您的方法,它也会导致运行时错误.Alert
需要写为alert
.
请解决该问题,然后返回结果.
问候,
—MRB
Javascript is case sensitive, so even if your method would have been triggered it would cause a runtime error.Alert
needs to written asalert
.
Please fix that and come back with your results.
Regards,
—MRB
这篇关于div标签的javascript onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文