在我的页面中有一个表格,每个表格行都有两个链接标记。我想通过点击第一个来调用秒,因为我想为第一个href中的第二个href添加一些参数。第二个链接在彩色元素元素中打开。
标签是。
<a id="linkToHiddenATag" href=" '#'.<?php echo $row['employee_id'];?>/<?php echo$row['supervisor_id'];?>" title="Product Operation List">Click for production entry</a>
<a class ="add cboxElement" href="#" id="hiddenATag" ></a>
完整的表格如下:
HTML
<div id="searchPanel">
<table id="searchTable" class="dataTable">
<thead>
<tr>
<th style="text-align: left; width: 8%;">SL</th>
<th style="text-align: left; width: 12%;">Employee Code</th>
<th style="text-align: left; width: 12%;">Employee Name</th>
<th style="text-align: left; width: 12%;">Designation</th>
<th style="text-align: left; width: 10%;">Entry Date</th>
<th style="text-align: left; width: 36%;">Entry</th>
<th style="text-align: center; width: 10%;">D'active</th>
</tr>
</thead>
<tbody>
<?php $loopCount = 1; if(isset($employeeData)){ foreach ($employeeData as $key => $row):?>
<tr id="tr_<?php echo $row['employee_id']; ?>">
<td style="text-align:center;"><input type="text" class="supervisorwiseSerial" id="supervisorwiseSerial_<?php echo $row['employee_id'];?>" name="supervisorwiseSerial_<?php echo $row['employee_id'];?>" value="<?php echo $row['supervisorwise_serial'] ;?>"></td>
<td><?php echo $row['employee_pre_code']."-".$row['employee_code'];?></td>
<td><?php echo $row['employee_name'];?></td>
<td><?php echo $row['designation_name'];?></td>
<td style="text-align: center;">
<input style="width: 80px;" type="text" placeholder="dd.mm.yyyy" class="dateOfProduction_" name="dateOfProduction_" id="dateOfProduction_<?php echo $row['employee_id']; ?>" required />
</td>
<td style="text-align: center;"><a class="btn btn-success btn-xs" id="setSerial_<?php echo $row['employee_id'];?>" role="button" href="#" >Set serial </a> || <a id="linkToHiddenATag" href="<?php echo '#'.base_url();?>production_entry/showOperationList/<?php echo $row['employee_id'];?>/<?php echo$row['supervisor_id'];?>" title="Product Operation List">Click for production entry</a></td>
<td style="text-align:center"><a class="btn btn-warning btn-xs" id="deActiveEmployee" href="<?php echo base_url().'employee'.'/'.'#'.'editOrDeactivate'.$row['employee_id'];?>" target="_blank">D'active Emp</a></td>
<input type="hidden" id="employeeId" value="<?php echo $row['employee_id']; ?>">
<input type="hidden" id="unit_<?php echo $row['employee_id']; ?>" value="<?php echo $row['unit_id']; ?>">
<input type="hidden" id="floor_<?php echo $row['employee_id']; ?>" value="<?php echo $row['floor_id']; ?>">
<input type="hidden" id="section_<?php echo $row['employee_id']; ?>" value="<?php echo $row['section_id']; ?>">
<input type="hidden" id="subsection_<?php echo $row['employee_id']; ?>" value="<?php echo $row['subsection_id']; ?>">
<input type="hidden" id="incharge_<?php echo $row['employee_id']; ?>" value="<?php echo $row['incharge_id']; ?>">
</tr>
<?php $loopCount++; endforeach;}?>
</tbody>
</table>
</div>
<div class="panel-footer" style="text-align: right;" id="searchPanelFooter">
<a id="saveAll" name="saveAll" class="btn btn-success btn-md" role="button" href="#">Save All</a>
<a class ="add cboxElement" href="#" id="hiddenATag" ></a>
</div>
使用Javascript:
$(document).on('click', 'a#linkToHiddenATag', function() {
var url = $(this).attr("href");
var arrfor = url.split('/');
var lengthto = arrfor.length;
var employeeSysIdForOpList = arrfor[lengthto - 2];
var supervisorIdForOpList = arrfor[lengthto - 1];
var prodOpGrp = parseInt($('select#operationGroupSelect').val());
var newhref = '';
if ($.isNumeric(prodOpGrp)) {
newhref = '<?php echo base_url().'
production_entry / showOperationList / ';?>' + employeeSysIdForOpList + '/' + supervisorIdForOpList + '/' + prodOpGrp;
} else {
newhref = '<?php echo base_url().'
production_entry / showOperationList / ';?>' + employeeSysIdForOpList + '/' + supervisorIdForOpList;
}
$('a#hiddenATag').removeProp("href");
$('a#hiddenATag').prop("href", newhref);
$('a#hiddenATag').click();
});
问题是click事件只能运行一次。它永远不会再发射。我没能发现问题。如果有人可以提供帮助,那就很有帮助。
答案 0 :(得分:2)
我尝试了你的例子它正在运作。我从示例中删除了href以进行测试
问题:
1)我运行你的代码也显示 production_entry undefined
2)字符串连接错误也应该是这样的,如果它在新行中(使用+) 的 的
的 newhref = '<?php echo base_url().'+
production_entry +'/'+ showOperationList +'/'+ ';?>'
的
$(document).on('click', 'a#linkToHiddenATag', function() {
var url = $(this).attr("href");
var arrfor = url.split('/');
var lengthto = arrfor.length;
var employeeSysIdForOpList = arrfor[lengthto - 2];
var supervisorIdForOpList = arrfor[lengthto - 1];
$('body').append('clicked')
console.log("clicked")
$('a#hiddenATag').click();
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="linkToHiddenATag" href="#" title="Product Operation List">Click for production entry</a>
<a class="add cboxElement" href="" id="hiddenATag" onClick="console.log('ss')"></a>
&#13;
答案 1 :(得分:0)
我认为您应该使用$('a#hiddenATag').trigger('click');
代替$('a#hiddenATag').click();
答案 2 :(得分:0)
试试这个
$('#linkToHiddenATag').on('click',function(){
*/ Write your code */
});