gpt4 book ai didi

带名称的 JavaScript 提示

转载 作者:行者123 更新时间:2023-11-28 20:17:04 26 4
gpt4 key购买 nike

如果我的表单已完全填写,我如何提示“感谢您填写表单,“name”!”

function submit_onclick() {
if(confirm("Thanks for completing the form " + form.name.value))
document.forms[0].submit();
else
return false;
}

jquery-1.10.2.min.js 脚本 src="jquery.validate.min.js 这些是我通过 jquery 的外部内容。它在表单旁边进行验证。我只需要提示告诉“名称”,感谢您完成。

jsFiddled here

即使表单为空也会出现此提示。

最佳答案

扩展DesertIvy的答案,我认为如果您只是在表单完成验证后在网页上显示一条消息,那么对用户来说会少很多烦人的事情。这样会显得不那么突兀。像这样的事情:

<form id="myForm" action="http://example.com/formSubmit.php" method="post">
<div>
<input type="text" name="name">
<input type="submit">
</div>
</form>

JavaScript:

function validForm() {
// form validation - return true or false
}

function submit_onclick() {
if(validForm()) {
$('#myForm').submit(); // this will submit the form to the form action
}
}

然后在加载 formSubmit.php 页面时,您可以在 HTML 正文中显示您的消息。这是如果您的服务器端语言是 PHP:

<?php
if(isset($_POST['name'])
echo "Thanks for completing the form " . $_POST['name'] . ".";
else
renderFormBody(); // function for rendering the form body
?>

关于带名称的 JavaScript 提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19056218/

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