我想知道如何用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 :(得分:1)
最好在PHP端执行此任务,而不是在浏览器/客户端执行此任务。
要使用jQuery实现它,您必须找到具有独特内容的“a”标记,例如“id”。
试试这个:
HTML code:
<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>
祝你好运!
答案 1 :(得分: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>