在这里我想做,在改变我想要的状态时获取值id和状态,这里我只得到身份证,我无法获得状态(1或2或3),我没有'我知道该怎么做: -
function get_pstatus(_this){
var p_id=$(_this).closest('tr').find('#p_id').val();
var p_status=$(_this).closest('tr').find('#p_status').text();
console.log(p_status);
}

<table class="table table-striped table-bordered table-hover dataTables-example" id="">
<thead>
<tr>
<th>No.</th>
<th>Project Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
include('dbconfig.php');
$project = mysql_query("SELECT id,project_id,project_name FROM add_projects WHERE status !='1'");
for ($i=1;$p=mysql_fetch_assoc($project);$i++){
?>
<tr class="odd gradeX">
<td id="s_no"><?php echo $i;?><input id="p_id" type="hidden" value="<?php echo $p['id']?>"></td>
<td id="p_name"><?php echo $p['project_name']?></td>
<td id="p_status">
<form style=" margin-bottom: 0px;" id="project_status">
<select class="form-control" id="status" name="status" onchange="get_pstatus(this);" style="width:150px;">
<option value="">-- Select Status --</option>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
</form>
</td>
</tr>
<?php } ?>
</tbody>
</table>
&#13;
答案 0 :(得分:0)
您需要获取所选的选项值和文本,如下所示: -
function get_pstatus(){
var p_id = $('select#status').find('option:selected').val();
var p_status = $('select#status').find('option:selected').text();
}
或者
function get_pstatus(){
var p_id = $('#status :selected').val();
var p_status = $('#status :selected').text();
}
而不是onchange="get_pstatus(this);
写onchange="get_pstatus();
实施例: -
function get_pstatus(){
var p_id = $('#status :selected').val();
var p_status = $('#status :selected').text();
console.log(p_id);
console.log(p_status);
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="form-control" id="status" name="status" onchange="get_pstatus(this);" style="width:150px;">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
&#13;