2012-09-18 26 views
-3

如何在「showImages」jQuery - 如何獲取按鈕單擊時隱藏字段中存儲數組的值?

<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循環中。所以它們是動態生成的。

感謝,

+0

您可以發佈您原來的標記,並通過點擊該值應檢索每個按鈕指定? – undefined

+0

按鈕我的意思是點擊的跨度 – asifa

+0

我知道,你應該有其他的跨度元素,對吧? – undefined

回答

1

如果跨度和隱藏字段在循環再試試這個:

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); 

} 
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); 
}); 
相關問題