sfgk102 发表于 2012-3-22 15:33:34

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

我想实现一个这样的效果,鼠标移动到商品名称上显示“查看详情”,点击按钮在其下方弹出一个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><spanid="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>

如图:
data/attachment/album/201203/22/15322255w779xqxsc7cg88.png

80后 发表于 2012-3-25 14:16:54

用jquery 的 each 来遍历你的DIV的包含id的input
页: [1]
查看完整版本: 请问怎么向javascript中传递不通的id值