-3

如何在单击“showImages”时检索特定的隐藏字段值

<span class="isymbol" id="showImages" href="Javascript:Void(0);"></span>

<input type="hidden" name="hdnplaceid[<?php echo $k; ?>]" id="hdnplaceid" value="<?php echo $PackageDetailsSightSeeing[$k]['deal_place_id']; ?>">
<input type="hidden" name="hdncityid[<?php echo $k; ?>]" id="hdncityid" value="<?php echo $PackageDetailsSightSeeing[$k]['deal_city_id']; ?>">

我试过这个,但每次我得到相同的值,不管我点击的按钮是什么

$('.isymbol').click( function() {
   var placeid= $("#hdnplaceid").val();

   //   $("#hdnplaceid").val();
   var cityid=$("#hdncityid").val();
   alert(placeid);
   alert(cityid);
   loadImagePopupBox();
});

跨度和输入字段在 for 循环中。所以它们是动态生成的。

谢谢,

4

2 回答 2

1

如果 span 和 hidden 字段在循环中,那么试试这个:

php/html 代码:

<span class="isymbol" id="showImages" href="Javascript:Void(0);" onclick="show_hidden_value(<?php echo $k; ?>)"></span>

<input type="hidden" name="hdnplaceid<?php echo $k; ?>" id="hdnplaceid" value="<?php echo $PackageDetailsSightSeeing[$k]['deal_place_id']; ?>">
<input type="hidden" name="hdncityid<?php echo $k; ?>" id="hdncityid" value="<?php echo $PackageDetailsSightSeeing[$k]['deal_city_id']; ?>">

javascript代码:

function show_hidden_value(id){
  var placeid= $("#hdnplaceid"+id).val();


  var cityid=$("#hdncityid"+id).val();

  alert(placeid);
  alert(cityid);

}
于 2012-09-18T12:09:00.897 回答
0

HTML:

<span class="isymbol" id="[<?php echo $k; ?>]" href="Javascript:Void(0);"></span> 
<input type="hidden" name="hdnplaceid[<?php echo $k; ?>]" id="hdnplaceid" value="<?php echo $PackageDetailsSightSeeing[$k]['deal_place_id']; ?>">
<input type="hidden" name="hdncityid[<?php echo $k; ?>]" id="hdncityid" value="<?php echo $PackageDetailsSightSeeing[$k]['deal_city_id']; ?>">

jQuery:

$('.isymbol').click( function() {
    var id = this.attr("id");
    var placeid= $("#hdnplaceid"+id).val();
    var cityid=$("#hdncityid"+id).val();
    alert(placeid);
    alert(cityid);  
});
于 2012-09-18T12:56:11.890 回答