根据URL更改内容

时间:2013-04-03 16:21:12

标签: php javascript html url

我希望能够根据我网站的网址更改网页的html的特定值。例如,如果我想将值更改为'example',我会转到mysite.com/page.php?value=example

我是否可以在不必在php include脚本中设置每个值的情况下执行此操作?

2 个答案:

答案 0 :(得分:3)

php页上,更改此内容:

<p>This is sample text and the word example.</p>

到此:

<p>This is sample text and the word <?php echo $_GET['value']; ?></p>

这会将您网址中?value=后的任何值打印到页面上。

答案 1 :(得分:2)

您可以在jQuery代码中应用类似的内容来检查给定URL中的页面名称,然后更改该页面上特定部分的值!不需要PHP,这都是前端逻辑。

var urlspot = document.URL.split('/');
if((urlspot[3] == 'pagename')) { 
  $('#content').text('now i want to change my text on this page');
}

只需根据网址中的位置将urlspot [x]更改为相应的数字即可。它不一定是3.它可以是1,2,3,4等......你必须玩它。

相关问题