0

我做了这个打开2页的JS函数

 function edit(id){
    window.open('<?php echo site_url();?>store_out/store_out_print/'+id);
    window.open('<?php echo site_url();?>store_out/delivery_print/'+id);
    document.getElementById('print').target = '_blank';
}

我有该表显示用户可以选择一行并单击打印图像的所有可能记录,因此打开了两个页面:

 <?php
         for($i=0;$i<sizeof($storeout);$i++){ ?>
   <tr class="gradeZ" id="<?php echo $storeout[$i]->storeout_id;?>" onclick="edit(this.id); ">
                <td><?php printf("%06d",$i+1);?></td>
                <td><?php echo $storeout[$i]->storeout_id;?></td>
                <td><?php echo $storeout[$i]->storeout_modified_time;?></td>
                <td><?php echo $account[$i][0]->account_name;?></td>
                <td><?php echo $storeout[$i]->rof_id != 0 ? "R.O.F" : "S.O";?></td>


            </tr>
        <?php } ?>

我想当我选择特定行并单击打印图像时,执行两个函数来打开两个不同的页面(delivery/store_out)。

有什么想法吗?

4

1 回答 1

0

我将假设tdis in atr是在循环中以编程方式生成的(即,您将拥有多个 1 trtdimg)。我还将假设 jQuery 是可用的。

第一个问题是,如果您在循环中创建了超过 1 行,那么您将拥有一堆具有相同id="print". 这不是好的js。

store_out您应该将(或您尝试获取控制器的任何 id)附加到 id 属性。类似的东西id="print_<?php echo $thing->id;?>"。这将让您获得要传递给编辑功能的 id。我还会添加一个class="print"这将使以下内容更容易。所以,整行看起来像:

<td width="5%"><a id="print_<?php echo $thing->id; ?>" class="print" href="#" ><img src="<?php echo site_url();?>/images/print.png" border="0" title="Print" height="25" width="25"/> </a></td>

这将输出如下内容:

<td width="5%"><a id="print_1234" class="print" href="#" ><img src="http://example.com/images/print.png" border="0" title="Print" height="25" width="25"/> </a></td>

id其次,据我所知,您没有传递给该方法。考虑到您注意到上述内容,您可以从 id 属性中提取 id 。

$('.print').click(function(){
    var id = $(this).attr('id').split('_')[1];
    edit(id);
})
于 2013-01-30T20:27:36.440 回答