当特定按钮被点击时执行特定代码

Execute specific code when specific button is click one it

本文关键字:执行 代码 按钮      更新时间:2023-09-26

当单击其中一个按钮时,我一次只能执行一个脚本。单击按钮时,代码将一起执行2个脚本。如何一次只能执行一个脚本,而特定按钮执行特定脚本。谢谢你的帮助。下面是我的代码。

<html>
<head>
<script language="javascript" type="text/javascript">
    function popup(){
        window.location = 'testing.php?run=shell';
    }
    function popdown(){
        window.location = 'testing.php?run=shell';
    }
</script>
</head>
<body>
<input type="button" onclick="popup()" value="popup">
<?php
if(isset($_GET['run']) && ($_GET['run'] == 'shell')){
    echo shell_exec('sh bash_test.sh');
}
?>
<input type="button" onclick="popdown()" value="popdown">
<?php
if(isset($_GET['run']) && ($_GET['run'] == 'shell')){
    echo shell_exec('sh bash_run.sh');
}
?>
</body>
</html>

试试这个:

<html>
<head>
<script language="javascript" type="text/javascript">
    function popup(){
        window.location = 'testing.php?run=test';
    }
    function popdown(){
        window.location = 'testing.php?run=run';
    }
</script>
</head>
<body>
<input type="button" onclick="popup()" value="popup">
<?php
if(isset($_GET['run']) && ($_GET['run'] == 'test')){
    echo shell_exec('sh bash_test.sh');
}
?>
<input type="button" onclick="popdown()" value="popdown">
<?php
if(isset($_GET['run']) && ($_GET['run'] == 'run')){
    echo shell_exec('sh bash_run.sh');
}
?>
</body>
</html>

只需单独标记脚本

<html>
<head>
<script language="javascript" type="text/javascript">
    function popup(){
        window.location = 'testing.php?run=shell1';
    }
    function popdown(){
        window.location = 'testing.php?run=shell2';
    }
</script>
</head>
<body>
<input type="button" onclick="popup()" value="popup">
<?php
if(isset($_GET['run']) && ($_GET['run'] == 'shell1')){
    echo shell_exec('sh bash_test.sh');
}
?>
<input type="button" onclick="popdown()" value="popdown">
<?php
if(isset($_GET['run']) && ($_GET['run'] == 'shell2')){
    echo shell_exec('sh bash_run.sh');
}
?>
</body>
</html>