当标签的值或rel
属性发生更改时,我在运行 JS 函数时遇到问题,如下所示:anchor
anchor
<a id="ThemeImageLink1" runat="server" href="javascript:void(0)" class="preview"
rel="../Images/templateChooser/preview/preview1.jpg">
我正在从代码隐藏中更改 rel 标记值:
HtmlAnchor imageLink = (HtmlAnchor)getControlId(counter, "ThemeImageLink");
imageLink.Attributes.Add("rel","../Images/templateChooser/preview/preview2.jpg");
getControlId
用于FindControl()
从aspx
页面检索控制。
如果我在更改属性值的地方注释掉代码中的部分,则rel
jQuery 可以正常工作。然后jQuery脚本使用默认值rel
这是我调用函数的 jQuery 部分:
$(document).ready(function () {
imagePreview();
});
及功能实现:
this.imagePreview = function(){
xOffset = 10;
yOffset = 30;
$("a.preview").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#preview").remove();
});
$("a.preview").mousemove(function(e){
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
我也有其他 JavaScript 函数可以正常工作,但是这个给我带来了问题。你认为我应该在 PageLoad 方法上调用 JS 吗?