简体   繁体   English

以仅 html 的形式显示消息

[英]Show message in form with only html

Im creating a form and in this form I want a message to be displayed when the user clicks the submit button.我创建了一个表单,在这个表单中,我希望在用户单击提交按钮时显示一条消息。 Can this be done without php?这可以在没有 php 的情况下完成吗?

Instead of an input element with type="submit" , consider using a normal button with an onclick attribute.考虑使用带有onclick属性的普通按钮,而不是type="submit"input元素。 Do not specify any action attribute for the <form> element.不要为<form>元素指定任何action属性。

<form>
  <input id="usn" type="text" placeholder="Username" />
  <input id="psw" type="text" placeholder="Password" />
  <input type="submit" onsubmit="myFunction()" />
</form>
<script type="text/javascript">
  function myFunction() {
    var username = "The username you entered is: " + document.getElementById('usn').value + ". ";
    var password = "The password you entered is: " + document.getElementById('psw').value + ". ";
    alert(username + password);
  }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM