【问题标题】:check existense of div with id and insert some html code检查是否存在带有 id 的 div 并插入一些 html 代码
【发布时间】:2012-07-12 12:47:12
【问题描述】:

如何在某个 div 下方插入一些内容?

我的页面上有一个 jwplayer,它通常有一个 jwplayer-1 的 id,由 wordpress 的 jwplayer 插件插入。

我想要做的是在它的下方插入一个 div(如果存在)。

例如,如果我的页面有播放器,那么页面上的某处就会有

<div id="jwplayer-1>Player will appear here</div>

我想做的是检查该行是否存在,如果存在,则插入另一个 div,以便代码如下所示。

<div id="jwplayer-1>Player will appear here</div>
<div id="viewcount">Total Views: <?php showviews()?></div>

谢谢

【问题讨论】:

    标签: dynamic conditional jwplayer


    【解决方案1】:

    你可以这样做:

    $('<div id="viewcount">Total Views: X</div>').insertAfter($('#jwplayer-1'));
    

    【讨论】:

      【解决方案2】:

      如果你要将你的 div 放在另一个 div 中,你可以使用 jQuery 的 append 方法:

      html:

      <div id="container">
          <div id="jwplayer-1>Player will appear here</div>
      </div>
      

      javascript:

      $('.container').append('<div id="viewcount">Total Views: <?php showviews()?></div>');
      

      来源:

      http://api.jquery.com/append/

      【讨论】:

        猜你喜欢
        • 2016-01-05
        • 2014-01-24
        • 1970-01-01
        • 2010-10-12
        • 2014-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-27
        相关资源
        最近更新 更多