我有这样的代码:
<?php
$name = "edward";
$country = "Indonesia";
?>
<form id="bio">
<input type="text" id="name" value="<?= $name ?>">
<input type="text" id="country" value="<?= $country?>">
</form>
<button class="clear">Cancel</button>
因此,当第一次加载时,文本框根据我之前定义的变量填充。然后我在文本框名称或国家中更改/键入一些东西。如何使文本框值回到以前的值(文本框名称由爱德华填写,国家由印度尼西亚填写-都由它的默认值填写),当我按下取消按钮?谢谢你的帮助:)
In HTML5
use
<form>
<input type="text" id="name" placeholder="<?= $name ?>">
<input type="text" id="country" placeholder="<?= $country?>">
<button class="clear" type="reset">Cancel</button>
</form>
或者使用JavaScript
使用按钮的onclick将值设置为正常值:
<button class="clear" onclick="document.getElementById('name').value='<?=$name?>';document.getElementById('country').value='<?=$county?>';">Cancel</button>