dongshuo9350 2017-08-25 02:58
浏览 64
已采纳

如何在默认情况下将真实文本(不是灰色提示或可见空白建议)放在网页的HTML文本字段中?

I am using the "placeholder" attribute in HTML5. I use it in a PHP web page with an HTML section. It works as expected.

Here is my code (it was modified slightly from the w3schools website):

<!DOCTYPE html>
<html>
<body>

<form action="/nextpage.php">
  <input type="text" name="firstname" placeholder="John"><br>
  <input type="text" name="lastname" placeholder="Doe"><br>
  <input type="submit" value="Submit">
</form>

</body>
</html>

As a user with the web page I tried using a form with the placeholder element and I clicked submit, but it acts like the field is empty if I do not change the default text that appears in light gray.

I want the text to be real -- and not act as though the field is empty. If the user changes the placeholder text in the fields, then that is fine. But if the user does not touch the placeholder text, I want the "Submit" click to ingest the placeholder text as if the user typed it in manually. How do I do this? I tried a variety of different things, but I cannot get it to work. The text could appear black -- but this does not matter. I want the text to be in the field if the user does not delete it or change it.

  • 写回答

3条回答 默认 最新

  • douhuang2282 2017-08-25 03:11
    关注

    Also set the "value" param

     <input type="text" name="firstname" placeholder="John" value="John">
    

    It will have the user delete the placeholder but if nothing is changed then it is sent

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100