2015-02-26 49 views
-1

我想知道如何用PHP代码替换链接文本。我有这样的代码:用PHP代码替换文本

<div class='rmm' data-menu-title = "Navigation" data-menu-style = "custom"> <!-- data-menu-title = Input your Menu text (This is the text to the right of the mobilestate menu)--> 
<ul><li id="current_yes"><a href="#">HEM</a></li></ul> 
</div> 

,我希望它看起来魔神此:

<div class='rmm' data-menu-title = "Navigation" data-menu-style = "custom"> <!-- data-menu-title = Input your Menu text (This is the text to the right of the mobilestate menu)--> 
<ul><li id="current_yes"><a href="#"><?php echo $lang['MENU_HOME']; ?></a></li></ul> 

因此,如何在页面加载jQuery的改变呢?

谢谢。

+0

你想使用jQuery去改变它或你想用PHP来做到这一点?关于PHP的标题问题,但在你的问题内部问是用jQuery来做这件事......我很困惑。 – OscarGarcia

+0

这是完全令人困惑的,我认为Patrik希望PHP代码在与JS一起放入HTML时执行,但这不是它的工作方式:1.用户请求从浏览器到服务器的响应。 2.服务器使用PHP创建HTML + JS输出。 3. HTML + JS发送到浏览器。 4. HTML被渲染,JS在浏览器中被执行。 5.转到1并重复。 – mondjunge

回答

1

在PHP端而不是在浏览器/客户端执行此任务更好。

要使用jQuery来实现它,你必须找到一个独特的“a”标签,比如它的“id”。

试试这个:

HTML代码:

<div class='rmm' data-menu-title = "Navigation" data-menu-style = "custom"> 
    <!-- data-menu-title = Input your Menu text 
    (This is the text to the right of the mobilestate menu) --> 
<ul> 
    <li id="current_yes"> 
     <a href="#" id="link_I_want_to_change">HEM</a> 
    </li> 
</ul> 
</div> 

Javascript代码:

<script type='text/javascript'>//<![CDATA[ 
    $(window).load(function(){ 
     $("#link_I_want_to_change").html("Place your text here"); 
    });//]]> 
</script> 

在线试用这里: http://jsfiddle.net/OscarGarcia/g1wfeqkc/

祝你好运!

+1

又发生了什么事?另一个没有评论或解释的负面投票?我的回答有什么问题? – OscarGarcia

+0

大家好,谢谢你。我现在测试它。我会回到你身边。 –

+0

嘿,这不是真正的工作,它是HEM文本我想改变任何来自<?php echo $ lang ['MENU_HOME'];在这个文件中,我有这个:$ lang ['MENU_HOME'] ='Home';在这个文件中我有这个:$ lang ['MENU_HOME'] ='Home'; –

0

嘿,我有这样的:

<div class='rmm' data-menu-title = "Navigation" data-menu-style = "custom"> <!-- data-menu-title = Input your Menu text (This is the text to the right of the mobilestate menu)--> 
<ul><li id="current_yes"><a href="#" id="1">HEM</a></li></ul> 
</div> 

<script> 
var word = 'HEM'; 
var sent = $('#1').html().replace(word, '<?echo $lang['MENU_HOME']; ?>'); 
$('#1').html(sent); 
</script>