0

下面我有一个包含四个文本输入的表单:

<form id='updateForm'>

        <p><strong>Current Assessment's Date/Start Time:</strong></p>
        <table>
         <tr>
        <th>&nbsp;</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

4

1 回答 1

1
$('#currentId').val($(this).find('option:selected').val());
于 2012-12-14T21:45:06.590 回答