0

单击其中一个按钮时,我无法一次只执行一个脚本。单击按钮时,代码将一起执行 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>
4

2 回答 2

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>
于 2012-08-28T01:28:11.090 回答
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>
于 2012-08-28T01:28:21.997 回答