如果选中了单选,如何包含php文件

如果选中了单选,我需要包含一个speficif php文件


这是我的收音机:


echo '<input type="radio" name="vue" id="mois" value="mois" onclick="vues()"'; if($mois) {echo "checked"; }


echo '>

            <label for="mois">Mois</label>

      <input type="radio" name="vue" id="semaine" value="semaine" onclick="vues()"'; if($semaine) {echo "checked"; }

echo  '>

            <label for="semaine">Semaine</label>

      <input type="radio" name="vue" id="jour" value="jour" onclick="vues()"'; if($jour) {echo "checked"; }

echo  '>

            <label for="jour">Jour</label>';

我尝试这样做:


function vues(){

            if($('#mois').is(':checked')){

                  document.getElementById("test").innerHTML = "<?php include '../public/mois.php'; ?>";

            } else if ($('#semaine').is(':checked')){

                  document.getElementById("test").innerHTML = "<?php include '../public/semaine.php'; ?>";

            } else if ($('#jour').is(':checked')){

                  document.getElementById("test").innerHTML = "<?php include '../public/jour.php'; ?>";}

}

但是什么也没发生。


犯罪嫌疑人X
浏览 129回答 3
3回答

回首忆惘然

问题在于了解客户端和服务器端代码之间的区别。您正在将两者混合在一起,期望结果根本不可能发生。但是,另一种解决方案是利用ajax(或jquery负载)。function vues(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if($('#mois').is(':checked')){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $( "#test" ).load( "mois.php" );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if ($('#semaine').is(':checked')){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $( "#test" ).load( "semaine.php" );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if ($('#jour').is(':checked')){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $( "#test" ).load( "jour.php" );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }}

尚方宝剑之说

您无法通过javascript包含类似的php文件,因为加载后会解析php文件。无论您要尝试加载的内容如何,都可以通过ajax调用后端操作来加载它,然后再返回一个文件的内容,这样可能会更好。

慕莱坞森

PHP代码在服务器上运行。您可以加载已执行的PHP的渲染结果,但是从客户端注入PHP代码不是一个好习惯,即使可能存在安全隐患。
打开App,查看更多内容
随时随地看视频慕课网APP