如何将术语slug作为参数传递给ajax函数

时间:2012-11-21 12:21:50

标签: jquery parameter-passing href

这是脚本的原始代码

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”值i,e。 term-&gt; slug到变量$ mainCat。我怎么能这样做,请帮助我

2 个答案:

答案 0 :(得分:1)

您似乎想在Click事件回调函数中执行此操作,只需使用:

var $mainCat=$(this).val();

答案 1 :(得分:0)

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