我在用jQuery AJAX搞怪,偶然发现了一个奇怪的地方(或者我缺乏理解:).这是我的ASPX主页的代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="jQuery_Test.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btnGo').click(function() {
$.ajax({
type: "GET",url: 'GetValues.aspx',contentType: 'text/html',success: function (html) { $("#Yo").append(html); }
});
})
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p id="Yo">Yo there!</p>
<br />
<a href="#" class="yo">Yo there!</a>
<br />
<a href="#">I'm in a DIV!</a>
<br />
<button id="btnGo">Go</button>
</div>
<br />
<br />
<a href="#">I'm not in a DIV!</a>
</form>
</body>
</html>
这是“ GetValues.aspx”页面的代码背后:
使用系统;
namespace jQuery_Test
{
public partial class GetValues : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
Response.ContentType = "text/html";
Response.Write("<a href='#'>Hello World</a>");
Response.End();
}
}
}
我正在做的是,当单击主页上的“开始”按钮时,我希望将锚标记放置在段落旁边.
该代码确实有效,但是锚点“ Hello World”出现约1秒钟,然后消失.有人可以指出我做错了什么吗?我正在使用VS 2010 Ultimate随附的jQuery-1.3.2.mins.js.
干杯.
贾斯
最佳答案
使您的函数返回false;
$(document).ready(function () {
$('#btnGo').click(function() {
$.ajax({
type: "GET",success: function (html) { $("#Yo").append(html); }
});
return false;
})
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。