gpt4 book ai didi

javascript - 即使刷新后也保留文本框值

转载 作者:行者123 更新时间:2023-11-28 15:21:17 25 4
gpt4 key购买 nike

我想即使在页面刷新之后也保留文本框值,而不是成功提交。

使用 cookie 或使用 php session

下面是代码:

<div class="block-content collapse in"> 
<div class="alert alert-success"><i class="icon-info-sign"></i> Please Fill in required details</div>
<form class="form-horizontal" method="post" enctype="multipart/form-data">
<table style width="100%">
<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Client Name</b></label>
<div class="controls">
<input type="text" class="span8" name="name" id="name" placeholder="Name of Client" required>
</div>
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>ਨਾਮ</b></label>
<div class="controls">
<input type="text" class="span8" name="namepb" id="transliteratename" placeholder="ਨਾਮ" required>
</div>
</div>

</td>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="datepicker1"><b>Client's DOB</b></label>
<div class="controls">
<input type="text" class="span8" name="dob" id="datepicker1" placeholder="Date of Birth mm/dd/yyyy" required>
</div>
</div>
</td>

<td>
<div id="image-preview">
<label for="image-upload">Choose File</label>
<input type="file" name="Photo" id="image-upload" required/>
</div>
</td>

</tr>

<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Father's Name</b></label>
<div class="controls">
<input type="text" class="span8" name="fname" id="inputPassword" placeholder="Client Father's Name" required>
</div>
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>ਪਿਤਾ ਦਾ ਨਾਮ</b></label>
<div class="controls">
<input type="text" class="span8" name="fnamepb" id="transliteratefname" placeholder="ਪਿਤਾ ਦਾ ਨਾਮ" required>
</div>
</div>
</td>

<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Mobile Number</b></label>
<div class="controls">
<input type="text" class="span8" name="mobile" id="mobile" placeholder="Client's Mobile Number" required>
</div>
</div>

</td>
</tr>

<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Address</b></label>
<div class="controls">
<textarea class="text" style="width:63%"; id="address" name="address" placeholder="Your Full Address" required></textarea>
</div>
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>ਪਤਾ </b></label>
<div class="controls">
<textarea class="text" style="width:63%"; id="transliterateaddress" name="addresspb" placeholder="ਪੂਰਾ ਪਤਾ" required></textarea>
</div>
</div>
</td>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Landline</b></label>
<div class="controls">
<input type="text" class="span8" name="landline" id="landline" placeholder="Client's Landline" required>
</div>
</div>
</td>
</tr>
<tr>

<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>City</b></label>
<div class="controls">
<input type="text" class="span8" name="city" id="inputPassword" placeholder="VPO / City" required>
</div>

<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>ਸ਼ਹਰ</b></label>
<div class="controls">
<input type="text" class="span8" name="citypb" id="transliteratecity" placeholder="ਵ.ਪ.ਓ / ਪਸ਼ਹਰ" required>
</div>
</div>
</td>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Tehsil</b></label>
<div class="controls">
<input type="text" class="span8" name="tehsil" id="inputPassword" placeholder="Tehsil" required>
</div>

<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>ਤੇਹ੍ਸਿਲ</b></label>
<div class="controls">
<input type="text" class="span8" name="tehsilpb" id="transliteratetehsil" placeholder="ਤੇਹ੍ਸਿਲ " required>
</div>
</div>
</td>
</tr>
<p> </p>
<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Distt.</b></label>
<div class="controls">
<input type="text" class="span8" name="distt" id="inputPassword" placeholder="District" required>
</div>
</div>
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>ਡਿਸਟ੍ਰਿਕ</b></label>
<div class="controls">
<input type="text" class="span8" name="disttpb" id="transliteratedistt" placeholder="ਡਿਸਟ੍ਰਿਕਟ" required>
</div>
</td>

<td>
<label class="control-label" style="font-size: 16px;" for="inputPassword"><b>Any Add. Details</b></label>
<div class="controls">
<select name="add" id="add" required>
<option value="">---Select---</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
</div>
</td>
</tr>

<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" id="la-add-address" for="inputPassword"><b>Additional Address</b></label>
<div class="controls">
<textarea class="text" style="width:63%"; id="addaddress" name="addaddress" placeholder="Your Full Address"></textarea>
</div>
</div>
</td>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" id="la-add-city" for="inputPassword"><b>City</b></label>
<div class="controls">
<input type="text" class="span8" name="addcity" id="addcity" placeholder="VPO / City">
</div>
</div>
</td>
</td>
<tr>
<td>

<div class="control-group">
<label class="control-label" style="font-size: 16px;" id="la-add-mob" for="inputPassword"><b>Mobile</b></label>
<div class="controls">
<input type="text" class="span8" name="addmob" id="addmob" placeholder="Client's Mobile Number">
</div>
</div>
</td>
<td>

</td>
</tr>

<tr>
<td>
<div class="control-group">
<label class="control-label" style="font-size: 16px;" for="inputEmail"><b>Type of Loan</b></label>
<div class="controls">
<select name="loantype_id" class="chzn-select" required/>
<option></option>
<?php $loan_type=mysql_query("select * from loan_type")or die(mysql_error());
while ($row=mysql_fetch_array($loan_type)){
?>
<option value="<?php echo $row['loantype_id']; ?>&nbspName&nbsp<?php echo $row['loanname']; ?>"><?php echo $row['loanname']; ?></option>
<?php } ?>
</select>
</div>
</div>
</td>
</tr>

<tr>
<td>
<div class="control-group">
<div class="controls">
<button name="save" id="save" data-placement="right" title="Click here to Save your new data." class="btn btn-primary"><i class="icon-save"></i> Next...</button>
</div>
</div>
</td>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$('#save').tooltip('show');
$('#save').tooltip('hide');
});
</script>

</tr>
</table>

</form>

如果有任何想法可以使用 Cookie 或使用 PHP Session 来解决此问题。

最佳答案

噢耶!!您可以使用 HTML5 的 localStoragesessionStorage

sessionStorage 将保留它直到 session 处于事件状态,但是localStorage 将保留它,直到您手动删除它。

请参阅下文,了解将其存储在其中任何一个中的方法:

存储:

localStorage.setItem('somekey','textboxValue') 
//or
sessionStorage.setItem('somekey','textboxvalue')

检索

localStorage.getItem('somekey')
//or
sessionStorage.getItem('somekey');

关于javascript - 即使刷新后也保留文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31311121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com