我写了这样的代码
<?php
$extCount = 0;
foreach($this->externalReferal as $externalReferal)
{
$extCount++;
?>
<div class='fieldtestPct' >
<div class='fieldItemLabel'>
<label for=''><?php echo $externalReferal->getConsultantname(); ?> ( <?php echo $externalReferal->getSpeciality(); ?> )</label>
</div>
<div class='fieldItemValue'>
<input type='checkbox' class='ext_ref_list<?php echo $extCount; ?>' name='ext_ref_cons[]' value="Consultant<?php echo $extCount ?>" >
</div>
</div>
<div class='fieldtestPct'>
<div class='fieldItemLabel'>
<label for=''>Current Visit</label>
</div>
<div class='fieldItemValue'>
<input type='checkbox' class='current_visit<?php echo $extCount; ?>' name='current_visit[]' value="" onClick ='currentVisit(this.class)'>
</div>
</div>
<div class='fieldtestPct'>
<div class='fieldItemLabel'>
<label for=''>Full Data</label>
</div>
<div class='fieldItemValue'>
<input type='checkbox' class='full_data<?php echo $extCount; ?>' name='full_data[]' value="" onClick='fullData(this)'>
</div>
</div>
<div class='clear'></div>
<?php
}
?>
在这里,我需要对复选框单击进行动态操作。我如何将选定的元素类/数据传递给javascipt。
最佳答案
使用this.className
而不是this.class
。
https://developer.mozilla.org/en/DOM/element.classname
关于php - onclick将元素的类传递给javascript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3369948/