我可以在PHP中实现这个简单的事情吗?

时间:2015-11-02 03:18:55

标签: php html css

基本上,我希望h1标签内的任何内容都复制到h2标签。请看下面的示例。

<!DOCTYPE html>
<html>
<body>

<h1>whatever is inside here, needs to also be inside the H2 tag.</h1>

<h2>whatever is inside h1 tag, it should also be here</h2>

</body>
</html>

在我的网站上,我有大约五个不同的标题标签,我需要手动复制粘贴到每个标签,所以我只想做一次并让它们都一样。

4 个答案:

答案 0 :(得分:1)

  

"Thank you Fred. Your answer worked. – John"

根据评论中的a comment I left并附加说明:

回显您可以在<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.chotoxautinh.controller.MainController"> <children> <ImageView focusTraversable="true" layoutX="735.0" layoutY="521.0" pickOnBounds="true" preserveRatio="true" styleClass="ruleButton" AnchorPane.bottomAnchor="25.0" AnchorPane.rightAnchor="23.0"> <cursor> <Cursor fx:constant="HAND" /> </cursor> <image> <Image url="@../../../../resources/images/rule-button.png" /> </image> </ImageView> <ImageView fitHeight="600.0" fitWidth="800.0" pickOnBounds="true"> <image> <Image url="@../../../../resources/images/background.png" /> </image> </ImageView> <VBox alignment="CENTER" layoutX="510.0" layoutY="172.0" prefHeight="330.0" prefWidth="290.0" spacing="29.0" styleClass="mainButtonLayout"> <children> <Button defaultButton="true" focusTraversable="false" mnemonicParsing="false" opacity="0.7" prefHeight="47.0" prefWidth="220.0" text="CLASSIC MODE"> <cursor> <Cursor fx:constant="HAND" /> </cursor> </Button> <Button defaultButton="true" focusTraversable="false" mnemonicParsing="false" opacity="0.7" prefHeight="47.0" prefWidth="220.0" text="ENDLESS MODE"> <cursor> <Cursor fx:constant="HAND" /> </cursor> </Button> <Button defaultButton="true" focusTraversable="false" mnemonicParsing="false" opacity="0.7" prefHeight="47.0" prefWidth="220.0" text="MULTIPLAYER"> <cursor> <Cursor fx:constant="HAND" /> </cursor> </Button> <Label style="-fx-text-fill: #333;" text="Designed by ChoToXauTinh - ©2015 Paduvi.Ltd" translateY="33.0" /> </children> </VBox> </children> </AnchorPane> 标记内传递/回显的指定变量:

<h2>

答案 1 :(得分:0)

您可以使用两种方法。一个是@Fred ii建议的另外一个,

您必须将h2标记与h1绑定到某个类。

像这样,

$("h2.def").html($("h1.abc").html());
$("h2.xyz").html($("h1.second").html());

工作demo

请务必尝试@Fred ii建议的内容。

答案 2 :(得分:0)

这个怎么样?

<?php

    $h1 = "i'm Heading 01";
    $h2 = "i'm Heading 02";

?>

在HTML中

<!DOCTYPE html>
<html>
    <body>

        <!-- <h1>whatever is inside here, needs to also be inside the H2 tag.</h1> -->
        <h1><?php echo $h1 ?></h1>

        <!-- <h2>whatever is inside h1 tag, it should also be here</h2> -->
        <h2><?php echo $h2 ?>, <?php echo $h1 ?></h2>

    </body>
</html>

答案 3 :(得分:0)

只需创建一个变量并在标题上指定要使用的值:

<?php $title = "Stackoverflow!"; ?>
<!DOCTYPE html>
<html>
<body>

<h1><?php echo $title; ?></h1>

<h2><?php echo $title; ?></h2>

</body>
</html>

或者如果要将其用于多个页面,请创建一个包含配置的单独文件,并将其包含在您需要的位置。

的config.php

<?php $title = "Stackoverflow!"; ?>

page1.php中

<?php include("config.php") ?>
<!DOCTYPE html>
<html>
<body>

<h1><?php echo $title; ?></h1>

<h2><?php echo $title; ?></h2>
<p>This is page 1!</p>
</body>
</html>

使page2.php

<?php include("config.php") ?>
<!DOCTYPE html>
<html>
<body>

<h1><?php echo $title; ?></h1>

<h2><?php echo $title; ?></h2>
<p>This is page 2!</p>
</body>
</html>