用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2775|回复: 1
收起左侧

[HELP] 请问怎么向javascript中传递不通的id值

[复制链接]
发表于 2012-3-22 15:33:34 | 显示全部楼层 |阅读模式
我想实现一个这样的效果,鼠标移动到商品名称上显示“查看详情”,点击按钮在其下方弹出一个div,内容为所选商品的一些属性,如果是一个商品到好实现,但商品时数组遍历出来的,id值不固定,怎么将div的id值传到javascript脚本中?,求大家帮帮忙啊!
以下是一个代码:

<html>
<head>
    <script type="text/javascript" src="/jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    $("#1").click(function(){
        $("#2").show("slow");
    }).mouseout(function(){
        $("#2").hide();
    });
    });
    </script>
</head>

<body>
    <ul>
        <!-- <?php if ($cart = $this->cart->contents()) { ?>
            <?php foreach ($cart as $item){ ?> -->
            <li>
                <table width="380px" border="0" cellspacing="0" cellpadding="0" height="35">
                 <tr>
                     <td><input name="" type="checkbox" value="" /></td>
                     <td><span  id="1" title="查看详情">极品蓝山... </span></td>
                     <td><span class="coffee">H杯</span> <span class="yellow">¥35</span></td>
                     <td>&nbsp;</td>
                     <td>&nbsp;</td>
                     <td>&nbsp;</td>
                </tr>
                </table>
            </li>
        <div id="2" style="border-bottom: 1px dashed #999999;height: 35px;width: 380px;display:none;">
            您选择了:极品蓝山咖啡,大杯,热杯,加糖
        </div>
        <!-- <?php } ?>
    <?php } ?> -->
    </ul>
</body>
</html>

如图:


发表于 2012-3-25 14:16:54 | 显示全部楼层
用jquery 的 each 来遍历你的DIV的包含id的input

本版积分规则