Home >Backend Development >PHP Tutorial >既保证打开页面时给文本框默认初始值,且在submit后文本框内容不消失

既保证打开页面时给文本框默认初始值,且在submit后文本框内容不消失

WBOY
WBOYOriginal
2016-06-23 13:33:42990browse

请教各位前辈一个问题。
现在有一个文本框,为了使其在submit提交之后内容不消失,于是我这样写:

<input type="text" name="test" value="<?=$_POST['test'];?>" />

可是,我又打算在打开页面时给此文本框一个默认值(就得给value初始化一个值),这两个问题怎么兼容?


回复讨论(解决方案)

跳转网页的提交,你就得自己赋值给文本框 的value
ajax的提交,不把文本框的value赋值为空就行了

<input type="text" name="test" value="<<?= empty($_POST['test'])?$default:$_POST['test'];?>" />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn