如何访问同一php文件中php代码段中的html内容


How to access the html contents in the php code segment within the same php file?

我有一个包含html内容和php内容的php文件。

<body>
    <a href="settings.php" onclick="edit_enable()">
        Edit section
    </a>
    <div class="container" hidden name="Edit">
        <section class="ac-container">
            <p>This is the Edit Section</p>
        </section>
    </div>
</body>

我有一个php段,其中包含函数edit_enable()

<?php
    function edit_enable() {
    }
?>

我希望此函数能够访问命名的"编辑",并更改可见性以及其中的其他属性。

//更新我只是添加了一个这样的例子,我的主要意图是访问/更改html内容,所有这些都使用php代码。

您还未使用一些html属性。您已经获取了一些表单属性值,并将它们放置在<div中。不支持此操作。

我已经重写了您的html,将hidden放在一个有意义的style属性中。并将CCD_ 4属性重命名为广泛使用的CCD_。然后我放置了一个javascript函数来切换div 的显示

<body>
<a href="settings.php" onclick="edit_enable();">
    Edit section
</a>
<div class="container" style="display:none;" id="Edit">
    <section class="ac-container">
        <p>This is the Edit Section</p>
    </section>
</div>
<script>
    function edit_enable() {
        var div = document.getElementById('Edit');
        div.style.display = (div.style.display == 'block') ? '' : 'block';
        return false;
    }
</script>