Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要在外部使用变量JS并使用按钮发送数据吗_Javascript_Php_Jquery_Function_Variables - Fatal编程技术网

Javascript 需要在外部使用变量JS并使用按钮发送数据吗

Javascript 需要在外部使用变量JS并使用按钮发送数据吗,javascript,php,jquery,function,variables,Javascript,Php,Jquery,Function,Variables,此脚本保存我单击的行的id。但现在我想做: “如果我单击按钮修改,然后更改url并将变量编号(这是行的id)发送到url(和下一页)。我不确定如何操作 我想将变量number保存在脚本外部,当我单击按钮modif时,我会将变量发送到另一个url 谢谢你的回答 HTML文件: <div id="page-wrapper" style=" padding-left: 20px"> <form method="post" name="employes1" action="em

此脚本保存我单击的行的id。但现在我想做: “如果我单击
按钮修改
,然后更改url并将变量
编号
(这是行的id)发送到url(和下一页)。我不确定如何操作

我想将变量
number
保存在脚本外部,当我单击
按钮modif
时,我会将变量发送到另一个url

谢谢你的回答

HTML文件

<div id="page-wrapper" style=" padding-left: 20px">
    <form method="post" name="employes1" action="employes.php">
        <div class="container-fluid">
            <div class="row">
                <div class=" text-center">
                    <button type="button"
                            class="btn btn-default"><?php echo '<a href="employesajout.php" > Ajouter un employé </a>'; ?></button>


                    <button type="submit" name="buttonmodif" id="modifon"> Mofidier informations</button>
                    <button type="submit" class="btn btn-default">Supprimer employé</button>
                    <button type="button" class="btn btn-default">Créer un contrat de travail</button>
                </div>

            </div>
            <div class="row table-responsive">

                <table class="table table-bordered table-hover" id="MyTable">
                    <thead class="-inverse">

                    <?php
                    $rep = $bdd->prepare('SELECT * from employee');
                    $rep->execute();
                    $resultat = $rep->fetchAll();
                    ?>


                    <tr>
                        <th>#</th>
                        <th>Nom</th>
                        <th>Prénom</th>
                        <th>Résidence</th>
                        <th>NAS</th>
                        <th>Date d'entré</th>
                        <th>Heure /semaine</th>
                        <th>Salaire brute</th>
                        <th>Salaire net</th>
                        <th>Vacance (s)</th>
                        <th>Email</th>


                    </tr>

                    </thead>
                    <tbody>

                    <?php foreach ($resultat as $row) {

                        echo "
                  <tr class ='clickable-row'>
                    <td>$row[0]</td>
                    <td>$row[1]</td>
                    <td>$row[2]</td>
                    <td>$row[3]</td>
                    <td>$row[4]</td>
                    <td>$row[5]</td>
                    <td>$row[6]</td>
                    <td>$row[7]</td>
                    <td>$row[8]</td>
                    <td>$row[9]</td>
                    <td>$row[10]</td>
                </tr>";

                    };

                    ?>

                    <script>

                        $(document).ready(function ($) {

                            $(".clickable-row").click(function () {

                                var number = parseInt($(this).closest('tr').children().eq(0).text());
                                console.log(number);

                            });


                            // active click hilight
                            $('td').click(function () {
                                $('tr').removeClass('active');
                                $(this).parent().addClass('active');
                            });


                        });

                    </script>


                    </tbody>
                </table>

            </div>

        </div>
    </form>

</div>

莫菲迪埃信息
雇主
劳动合同
#
笔名
名词
Résidence
NAS
进餐日期
豪尔/塞曼
萨拉尔畜生
萨拉尔网
假期(s)
电子邮件

click
函数外部声明变量。然后在使用变量的
按钮modif
按钮上绑定
click
处理程序。您可以向表单添加
type=“hidden”
输入,并将值放入其中

$(document.ready(function() {
    var number;

    $(".clickable-row").click(function() {
        number = parseInt($(this).closest('tr').children().eq(0).text());
        console.log(number);
    });

    $("#modifon").click(function() {
        $("#hiddenfield").val(number);
    });
});

我使用了:document.getElementById(“hiddenfield”).value=number;然后创建一个隐藏的输入,就像你说的,它正在工作。我想这是另一种方法?谢谢Barmar!是的,这是简单的Javascript方法。但是你使用的是jQuery,所以我用这种语法编写了它。