使用指定的键激活提交按钮

时间:2017-10-11 03:21:56

标签: javascript php html css

我的代码出现问题,我计划使用带有指定密钥的javascript来激活我的php。是否可以使用javascript使用指定的密钥激活具有唯一ID的按钮?或者更好的想法?

每个提交按钮都链接到我的数据库中的id,我想要的是通过使用指定的键而不是按下按钮来激活与其id链接的提交按钮

我有这个现有代码:

$sql = mysql_query("SELECT * FROM tb_topic GROUP BY t_id");
while ($row = mysql_fetch_assoc($sql)) {
    $t_id = $row['t_id'];
    $t_title = $row['t_title'];
    $t_desc = $row['t_desc'];
    $t_chap = $row['t_chap'];
    echo "<ul class='nav nav-sidebar'> ";
    echo "<li><a href=''><input type='submit'  name='$t_id' class='submitLink' value='$t_title'></a>";
    echo "</li></ul> ";

}


foreach($_POST as $key => $t_id){
    ${$key} = $t_id;

    $sql = mysql_query("SELECT * FROM tb_topic WHERE t_id = '$key'   ");
    while ($row = mysql_fetch_assoc($sql)) {
        $t_id = $row['t_id'];
        $t_titles = $row['t_title'];
        $t_descs = $row['t_desc'];
        $t_chaps = $row['t_chap'];
        $t_querys = $row['t_query'];


        $sql = mysql_query("SELECT * FROM tb_topic ORDER BY t_chap  DESC LIMIT 1   ");
        while ($row = mysql_fetch_assoc($sql)) {
            $t_chaps = $row['t_chap'];

            $nos = $t_chaps + 1;

            $up = mysql_query("UPDATE `tb_topic` SET `t_chap` = '$nos' WHERE t_id = '$t_id'  ");


        }
        echo "<script>window.location='i.php';</script>";

        if ($key == '4') {
            $up = mysql_query("UPDATE `tb_topic` SET `t_chap` = '0' ");
            echo "<script>window.location='i.php';</script>";


        }

    }


}
 <script>
document.onkeydown = function (evt) {
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if (keyCode == 81) {
       //activate submit button id: 1
       location.reload();
    }
}

document.onkeydown = function (evt) {
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if (keyCode == 87) {
       //activate submit button id: 2
       location.reload();
    }
}
</script>

0 个答案:

没有答案