duanlongling5308 2014-01-11 19:59 采纳率: 0%
浏览 49

将内容从标签加载到div中

I am trying to use a php variable that holds an html snippet to display inside a div when an <li> is clicked. The below code works if the variable only holds a string of text with no html. But as soon as I add html it stops working. What am I doing wrong?

I have updated the code based on help I received below, but it is still not working.

This works:

$(function() {
            $('#tab-1').click(function() {
                    alert('click event called!'); var tabcontent = "Test Content";
                    document.getElementById('top-tabs-content').innerHTML = tabcontent;
            });
            });

This doesn't:

$(function() {
            $('#tab-1').click(function() {
                    alert('click event called!'); var tabcontent = "<?php echo json_encode($tabcontent[0]);?>";
                    document.getElementById('top-tabs-content').innerHTML = tabcontent;
            });
            });
  • 写回答

2条回答 默认 最新

  • douzen1880 2014-01-11 20:03
    关注

    Try to replace

    var tabcontent = "<?php echo $tabcontent[1]; ?>"
    

    with

    var tabcontent = "'" + "<?php echo $tabcontent[1]; ?>" + "'";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制