社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Nipun Tharuksha

Nipun Tharuksha 最近创建的主题
Nipun Tharuksha 最近回复了
4 年前
回复了 Nipun Tharuksha 创建的主题 » jquery用户界面警报对话框与表单元素一起使用时将消失

问题在于,当您单击按钮时,表单将被提交。因为您正在为按钮使用类型为“提交”的输入,而该输入是包装在原处的 <form> 元素。

这个 HTML 认为要将表单数据发送到服务器进行处理,因此它将刷新 . 通过告知表格未提交,那么您的 jquery 工作并返回消息。只需添加 onsubmit="return false;" 用于表单标记。

'onsubmit=“return false;”做什么?

这基本上是通过javascript处理表单提交的,什么都不做,返回控制流

通过以下途径了解更多信息 www.codexpedia.com

这也会有帮助 prevent refresh of page when button inside form clicked

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="httpsz:/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>

function displayalert()
{
    $("<div>This is sample</div>").dialog();
}
</script>
</head>
<body>
 
 <form onsubmit="return false;">
<p>Select Items</p><br>
<input type="radio" name="checking">Item 1<br>
<input type="radio" name="checking">Item 2<br>
<input type="radio" name="checking">Item 3<br>
<input type="radio" name="checking">Item 4<br>
<input type="submit" onclick="displayalert()">
</form>
</body>
</html>