下面我有一个包含四个文本输入的表单:
<form id='updateForm'>
<p><strong>Current Assessment's Date/Start Time:</strong></p>
<table>
<tr>
<th> </th>
<td><input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Assessment:</th>
<td><input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Date:</th>
<td><input type='text' id='currentDate' name='Datecurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Start Time:</th>
<td><input type='text' id='currentTime' name='Timecurrent' readonly='readonly' value=''/> </td>
</tr>
</table>
</form>
现在下面我有一个下拉选项:
$sessionHTML .= sprintf("<option value='%s' style='color: %s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
现在我正在做的是下拉菜单中显示的值显示在相关的文本输入中,使用以下代码:
$('#sessionsDrop').change( function(){
if( $(this).val() !== '' ){
var text = $(this).find('option:selected').text();
var split = text.split(' - ');
$('#currentAssessment').val( split[0] );
$('#currentDate').val( split[1] );
$('#currentTime').val( split[2] );
}
});
但我遇到的唯一问题是如何显示要在文本输入<option value='%s' ... $dbSessionId ...
中显示的#currentId
选项的值?
答案 0 :(得分:1)
$('#currentId').val($(this).find('option:selected').val());