【发布时间】:2016-11-02 21:21:13
【问题描述】:
我有一个 jquery web 服务,它会影响同一页面上的 css 类工具提示。
问题是这样的;当页面最初加载时,工具提示 css 工作正常,但在 web 服务调用页面上的按钮后,工具提示类丢失并显示为标准视图。这是什么原因造成的?
c# Code Block
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SampleWeb {
public partial class Sample: System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
GetDataForPageLoad();
}
}
public void GetDataForPageLoad() {
StringBuilder sb = new StringBuilder();
lblData.Text = string.Format("<a title=\"click to view topic {0}.\" class=\"masterTooltip\"><img width=\"50px\" src='images/Chrysanthemum.jpg' alt=\"{0}\" /></a><br/>", "XXX");
}
[WebMethod]
public static string GetData() {
return string.Format("<a title=\"click to view topic {0}.\" class=\"masterTooltip\"><img width=\"50px\" src='images/Chrysanthemum.jpg' alt=\"{0}\" /></a><br/>", "XXX");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sample.aspx.cs" Inherits="SampleWeb.Sample" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>test</title>
<style type="text/css">
.tooltip {
display: none;
position: absolute;
border: 1px solid #b83e3e;
background-color: #d84949;
border-radius: 5px;
padding: 5px;
color: #fff;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function GetData() {
$.ajax({
url: 'http://localhost:6878/Sample.aspx/GetData',
type: 'POST',
data: '',
dataType: 'json',
contentType: 'application/json',
success: function(data) {
var obj = document.getElementById("lblData");
obj.innerHTML = obj.innerHTML + data.d;
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="Button1" type="button" value="Get" onclick="GetData();" />
<br />
<br />
<asp:Label ID="lblData" runat="server" Text=""></asp:Label>
<script type="text/javascript">
$(document).ready(function() {
// Tooltip only Text
$('.masterTooltip').hover(function() {
// Hover over code
var title = $(this).attr('title');
$(this).data('tipText', title).removeAttr('title');
$('<p class="tooltip"></p>')
.text(title)
.appendTo('body')
.fadeIn('slow');
}, function() {
// Hover out code
$(this).attr('title', $(this).data('tipText'));
$('.tooltip').remove();
}).mousemove(function(e) {
var mousex = e.pageX + 20; //Get X coordinates
var mousey = e.pageY + 10; //Get Y coordinates
$('.tooltip')
.css({
top: mousey,
left: mousex
})
});
});
</script>
</form>
</body>
</html>
【问题讨论】:
标签: javascript jquery css asp.net webmethod