使用PHP、AJAX、JQUERY获取表中隐藏tr的选定值
我的代码如下:使用PHP、AJAX、JQUERY获取表中隐藏tr的选定值,php,jquery,ajax,Php,Jquery,Ajax,我的代码如下: <form method ="post" id="myForm"> <table> <tr> <td>Classification socio <br /> professionnelle à l'embauche : </td> <td> <select name="droClassification" class="val
<form method ="post" id="myForm">
<table>
<tr>
<td>Classification socio <br /> professionnelle à l'embauche : </td>
<td>
<select name="droClassification" class="validate[required]" id="classification">
<option value="">choisir catégorie </option>
<option value="Ouvrier">Ouvrier</option>
<option value="Employe">Employé</option>
<option value="AgentMaitris">Agent de maitrise</option>
<option value="Cadre">Cadre</option>
<option value="Autre">Autre</option>
</select>
</td>
<td></td>
</tr>
<?php
if($_POST['droClassification'] == "Ouvrier" || $_POST['droClassification'] == "Employe"){
echo '<style type="text/css"> #trHide{display:none;}</style>';
}
?>
<tr id="trHide">
<td colspan="4">This is what I want to hide it, when I select on the Ouvrier or Employe</td>
</tr>
</table>
社会分类
职业内尔·埃姆巴切:
凯蒂戈里酒店
乌夫里埃
雇佣
德梅特里西探员
干部
奥特雷
这就是我想要隐藏它的地方,当我在Ouvrier或Employe上选择时
我需要:
当我选择on Ouvrier或Employee时,它将隐藏
标签
问题:
我使用PHP代码作为上面的代码,但它不起作用。那么你对此有什么想法吗?或者我应该使用哪种技术,比如AJAX、JQUERY、PHP?请帮帮我,谢谢。忘记
php
或ajax
,您不必为这种行为提出请求。使用
javascript
对于它,我将向您展示如何使用jQuery
实现它
使用jQuery
:jQuery('#classification').change(function() {
var selectedValue = $(this).val();
if(selectedValue == 'Ouvrier' || selectedValue == 'Employe') {
$('#trHide').hide();
}
});
如果要在更改为其他时显示分类,可以执行以下操作。jQuery('#classification').change(function() {
var selectedValue = $(this).val(),
$row = $('#trHide');
if(selectedValue == 'Ouvrier' || selectedValue == 'Employe') {
$row.hide();
} else {
$row.show();
}
});
更新:根据评论。更改为
class
而不是id
<tr class="trHide">
<td colspan="4">This is what I want to hide it, when I select on the Ouvrier or Employe</td>
</tr>
这就是我想要隐藏它的地方,当我在Ouvrier或Employe上选择时
然后将
$('#trHide')
更改为$('.trHide')
如果您想在某个时间隐藏效果,请使用jquery。感谢您的回答,它可以工作。但是如果我有很多
它将只隐藏第一个,而第二个或其他的则不会隐藏。那么我该如何解决这个问题呢?@Sealongmaly发生这种情况是因为id
必须是唯一的,如果您有多个具有相同值的id
,则只会选择第一个。所以改用一个类。哇,现在我把id改成了类。非常感谢@Ricardo Lohmann你真的帮了我很多:)