drhe80011 2013-12-26 22:27
浏览 17
已采纳

如何为多个元素使用相同的ID? - ArcText Wordpress作者名称JS

I am using [ArcText][1] to render the author names on a curvy path in wordpress. I am a beginner in PHP and JS.

Function:

function get_meta($id){
  echo <span id='example1'>".the_author_meta_r("display_name",$id)."</span>
}

ArcText Script:

var $example1   = $('#example1').hide();

google.load('webfont','1');

google.setOnLoadCallback(function() {
  WebFont.load({
    google        : {
      families    : ['Montserrat','Concert One']
    },
    fontactive    : function(fontFamily, fontDescription) {
      init();
    },
    fontinactive  : function(fontFamily, fontDescription) {
      init();
    }
  });
});

function init() {
  $example1.show().arctext({radius: 150, dir: -1});         
};

To display the author names I use:

<?php get_meta(1); ?><?php get_meta(2); ?><?php get_meta(3); ?>

Problem is that only (1) renders with curves and other two doesn't because three of them has the same id, and one element can have one id.

Can I rather use class? Since I dont know how many times user will use <?php get_meta(); ?>, thats why I am trying to avoid making multiple functions with multiple IDs.

  • 写回答

1条回答 默认 最新

  • douzhi1937 2013-12-26 23:04
    关注
    function get_meta($class){
      echo <span id='example1' class='useMultiTimes'>".the_author_meta_r("display_name",$class)."</span>
    }
    

    Then in the Javascript:

    var $example1   = $('.useMultiTimes').hide();
    

    Or, you can do:

    var $example1   = $("span[class='useMultiTimes']").hide();
    

    But this will possibly hide all the elements with the same class?

    <?php get_meta('useMultiTimes'); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误