Home  >  Article  >  Web Front-end  >  一个很简单的HTML运行机制问题。_html/css_WEB-ITnose

一个很简单的HTML运行机制问题。_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:25:17985browse

html机制

看代码
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>    <title></title>    <script type="text/javascript" src="script/jquery.min.js"></script>    <script type="text/javascript">        $(document).ready(function () {            $("#add").append("<input id='test' type='text' value=''/>");        });        function AddValue()        {            $("#test").val("测试值");        }    </script></head><body>    <form id="form1" runat="server">    <div id="add">    <input type="submit" value="测试" onclick="AddValue();"/>    </div>    </form></body></html>

这样为什么点击测试按钮。设置了文本框的值后又马上消失了。如果onclick后加上return false;后就可以。
点击input控件页面会刷新吗?

回复讨论(解决方案)

因为你点击的按钮是 submit 提交按钮,就触发了form的提交,相当重新发送了个请求给本页面(刷新页面/post/get),你可以改成type="button", 在你的函数处理完之后,再来 触发submit()

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