输入字段没有显示默认值

input fields not showing default value

本文关键字:显示 默认值 字段 输入      更新时间:2023-09-26

我有一个带有一些输入字段的表单。我在大多数上面设置了value="something here"。但是,当我在firefox中加载页面时,输入字段没有填充。

Firebug显示了一个value属性,其中包含正确的值。但是它没有显示在屏幕上。当我提交表单时,它也不传递值。

这是我的PHP脚本的输出,它只是转储数组。

}
[servDate] => 07-07-2011
[time1] => 8:00
[odo1] => 12345
[report1] => 
[time2] => 8:30
[odo2] => 12350
[report2] => 
[time4] => 9:00
[odo4] => 12359
[report4] => SUBJECT DEPARTS HOME
[time5] => 9:30
[odo5] => 12369
[report5] => SUBJECT ARRIVES AT WORK
[time98] => 9:35
[odo98] => 12369
[report98] => 
[time99] => 10:00
[odo99] => 12399
[report99] => 
[servHrs] => 
[id] => 
)

格式如下:

<form id="reportForm">
    Service Date: <input type="text" name="servDate" id="servDate" size="10" value="<? echo date("m-d-Y"); ?>" /><button id="servDateBtn"><img src="../includes/calendar.png" /></button><br />
    <table id="reportTable" name="reportTable">
        <tr>
            <th>&nbsp;</th>
            <th>Time</th>
            <th>Odometer</th>
            <th>Actions</th>
        </tr>
        <tr>
            <TD width="20px">&nbsp;</TD>
            <TD><INPUT type="text" name="time1" id="time1" size="4" /> 
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#time1').timepicker({
                        showPeriod: false,
                        showLeadingZero: false
                    });
                });
            </script>
            </TD>
            <td><input type="text" name="odo1" id="odo1" class="odo" size="6" /></td>
            <td><input type="text" name="report1" id="report1" size="42" value="Dispatched Investigator." readonly="readonly" /></td>
        </TR>
        <tr>
            <TD width="20px">&nbsp;</TD>
            <TD><INPUT type="text" name="time2" id="time2" size="4" /> 
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#time2').timepicker({
                        showPeriod: false,
                        showLeadingZero: false
                    });
                });
            </script>
            </TD>
            <td><input type="text" name="odo2" id="odo2" class="odo" size="6" /></td>
            <td><input type="text" name="report2" id="report2" size="42" value="Investigator arrived at first field location." readonly="readonly" /></td>
        </TR>
    </table>
    <table>
        <tr>
            <TD width="20px">&nbsp;</TD>
            <TD><INPUT type="text" name="time98" id="time98" size="4" /> 
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#time98').timepicker({
                        showPeriod: false,
                        showLeadingZero: false
                    });
                });
            </script>
            </TD>
            <td><input type="text" name="odo98" id="odo98" class="odo" size="6" /></td>
            <td><input type="text" name="report98" id="report98" size="42" value="Investigator departed last field location." readonly="readonly" /></td>
        </TR>
        <tr>
            <TD width="20px">&nbsp;</TD>
            <TD><INPUT type="text" name="time99" id="time99" size="4" /> 
            <script type="text/javascript">
                $(document).ready(function() {
                    $('#time99').timepicker({
                        showPeriod: false,
                        showLeadingZero: false
                    });
                });
            </script>
            </TD>
            <td><input type="text" name="odo99" id="odo99" class="odo" size="6" /></td>
            <td><input type="text" name="report99" id="report99" size="42" value="Investigator suspended." readonly="readonly" /></td>
        </TR>
    </table>
    <br /><button id="addEntry">Add Entry</button>&nbsp;<button id="delEntry">Delete Entry</button>
    <br />
    Service Hours: <input type="text" name="servHrs" id="servHrs" size="4" />
    <input type="hidden" name="id" class="client" value="<? echo $id ?>" />
</form>

在jquery对话框中打开。

我页面上的其他表单在一个对话框中打开并且工作正常。我已经证实我没有使用任何重复的id或NAME标签。更奇怪的是,有时它能工作,有时却不能。

出于安全原因,我不允许向您展示实际页面,因为该系统包含机密客户信息。

是否只在页面重新加载时发生?如果是这样的话,很可能是因为Firefox记住了旧的价值观。如果在新标签页中打开页面,会发生这种情况吗?

所以我知道这个问题已经问了很长时间了。但是,因为这里没有有效的答案,也没有帮助人们在未来:

如前所述,

浏览器不存储defaultValue。但是,使用元标签来指导浏览器根本不缓存是一个非常糟糕的解决方案。

:

这个问题甚至成为一个问题是(在我的情况下)应用程序正在分配一个空的defaultValue,当来自服务器的数据进来时,它没有更新它。

解决方案:

避免defaultValue重赋给实际值。当实际值可用时,仅呈现输入字段