问题描述
$('#content')。replaceWith(< div>+<?php echo $ tableau_Text?> +< / div>);
但是不适合我。它对我没有任何意义。当我将 PHP代码
更改为静态类型时:
$( '#content')。replaceWith(< div> Hello World< / div>);
它可以完美地与此相符。
我的html#内容定义是: -
< div id =content>
<?php echo $ show_menu;?>
< / div>
有什么想法吗?非常感谢!
更新:
var $ tableau_text
看起来像这样:
$ tableau_Text =< ul class ='object_list'id ='object_list'data -role ='listview'data-inset ='true'data-theme ='c'> $ TableauText< / ul>;
其中 $ TableauText
是相同的格式。
$ TableauText =< li class ='menuA'id ='menuA'data-role ='list-divider'data -icon ='false'> River Flow< / li>
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Rossiniere< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Montsalvens< / a>< /立GT;
< li class ='menuA'id ='menuA'data-role ='list-divider'data-icon ='false'> Lake Level< / li>
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Rossiniere< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Montsalvens< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Lessoc< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Rossens< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Maigrauge< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Schiffenen< / a>< /立GT;
< li class ='menuB'id ='menuB'data-icon ='arrow-r'>< a href ='#'target ='foo'> Maigrauge< / a>< /立GT;
解决方案:我粘贴了几个具有相同ID的列表元素,在这里,这让我的代码变得疯狂......
试试这个:
$('#content')。replaceWith(< div> +<?php echo json_encode($ tableau_Text);?> +< / div> ;);
鉴于:
$ TableauText ='hello world';
$ tableau_Text =
< ul class ='object_list'id ='object_list'data-role ='listview'data-inset ='true'data-theme ='c' >
$ TableauText
< / ul>;
浏览器将会显示:
<$ p $数据 - 角色='列表视图'数据
$('#content')。replaceWith(< div> +\\\
< ul class ='object_list'id ='object_list' -inset ='true'data-theme ='c'> \\\
hello world \\\\\
< \ / ul>+< / div>)
其中为
hello world
I am trying to execute this code in javascript:
$('#content').replaceWith("<div>" + <?php echo $tableau_Text?> + "</div>");
But is not working for me. It shows nothing to me. When I change the PHP code
for something static like:
$('#content').replaceWith("<div>Hello World</div>");
it works perfectly with that.
My html #content definition is:--
<div id="content">
<?php echo $show_menu;?>
</div>
Any idea? Thank you very much!
UPDATE:
The var $tableau_text
looks like this:
$tableau_Text = "<ul class='object_list' id='object_list' data-role='listview' data-inset='true' data-theme='c'>$TableauText</ul>";
Where $TableauText
are the list items in the same format.
$TableauText = <li class='menuA' id='menuA' data-role='list-divider' data-icon='false'>River Flow</li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Rossiniere</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Montsalvens</a></li>
<li class='menuA' id='menuA' data-role='list-divider' data-icon='false'>Lake Level</li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Rossiniere</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Montsalvens</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Lessoc</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Rossens</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Maigrauge</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Schiffenen</a></li>
<li class='menuB' id='menuB' data-icon='arrow-r'><a href='#' target='foo'>Maigrauge</a></li>
Solution: I had several list elements with the same id which I didn't realized after I paste it here and that was making my code crazy...
Try this:
$('#content').replaceWith("<div>" + <?php echo json_encode($tableau_Text); ?> + "</div>");
Given:
$TableauText = 'hello world ""';
$tableau_Text = "
<ul class='object_list' id='object_list' data-role='listview' data-inset='true' data-theme='c'>
$TableauText
</ul>";
The browser will see:
$('#content').replaceWith("<div>" + "\n <ul class='object_list' id='object_list' data-role='listview' data-inset='true' data-theme='c'>\n hello world \"\"\n <\/ul>" + "</div>")
Which renders as
hello world ""
这篇关于用PHP替换HTML替换函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!