【发布时间】:2019-07-04 01:55:19
【问题描述】:
我有一个小问题,我有以下代码,想在我的网站上添加语言切换。 假设我有一个 header.php 和一个 index.php。 我想在 header.php 中包含按钮和脚本。 Header.php 包含在 index.php 中。如何从 index.php 访问标头中的函数?
我的代码:
在 Header.php 中
<head>
<style type="text/css">
body.fr > p[lang=en] {
display: none;
}
body.en > p[lang=fr] {
display: none;
}
</style>
</head>
<button onclick="document.body.className='en'">English</button>
<button onclick="document.body.className='fr'">French</button>
在Index.php中
<?php
include('header.php');
?>
<body class="en">
<p lang="en">This is English</p>
<p lang="fr">This is French</p>
</body>
如果我点击按钮,文本不会改变。我假设我必须将 header.php 与 index.php 内容集成,但如何?
【问题讨论】:
-
嗨 :) 为什么在 header.php 中有按钮?以及他们为什么退出
body? -
为什么在 header.php 和 index.php 文件中都有按钮?
-
@MoshFeu 因为我不喜欢在每一页上导入按钮。我有很多页面。像 hello.php 和 world.php 一样,我希望标题中的按钮包含在所有文件中。
-
@OmariCelestine 对不起我的错误
-
@M.Antony 按钮应该在正文中,css如果是内联的,应该作为正文中的最后一个内容放置。