当特定按钮单击它时执行特定代码

时间:2012-08-28 01:24:18

标签: php javascript shell button

我有一个问题就是只在单击其中一个按钮时执行其中一个脚本。单击按钮时,代码一起执行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>

2 个答案:

答案 0 :(得分:0)

只需单独标记脚本

<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>

答案 1 :(得分:0)

试试这个:

<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>