Javascript 需要在外部使用变量JS并使用按钮发送数据吗
此脚本保存我单击的行的id。但现在我想做: “如果我单击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
按钮修改
,然后更改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,所以我用这种语法编写了它。