2012-11-21 34 views
0

這是腳本如何術語塞傳遞到AJAX功能參數

var $mainCat=$('#main_cat').val(); 

的原代碼,我用這個

var $mainCat=$('#<how to pass the slug here>').val(); 

echo '<ul>'; 
    foreach ($termchildren as $child) { 
    $term = get_term_by('id', $child, $taxonomyName); 
    echo '<li><a href="#" id=' .$term->slug. '>' . $term->name . ' </a></li>'; 
?> 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script> 
<script type="text/javascript"> 
$(function() 
{ 
    $('a#<?php echo $term->slug; ?>').click(function() 
    { 
    $('#pop-up1').show(); 
    $('#pop-up').show(); 
    <?php echo $term->slug; ?> 
     var $mainCat=$('#<how to pass the slug here>').val(); 

取代現在我需要通過「a href」價值,例如, term-> slug到變量$ mainCat。我如何能做到這一點,請幫我

回答

1

,因爲它似乎你想要做你的點擊事件的回調函數裏面,只要使用此:

var $mainCat=$(this).val(); 
0
var idCat = "<?php echo $term->slug; ?>" 
var $mainCat = $('#' + idCat).val();