gpt4 book ai didi

javascript - qTip 和动态添加元素问题

转载 作者:行者123 更新时间:2023-12-02 18:04:30 25 4
gpt4 key购买 nike

我有一个包含 UpdatePanel 的页面,我在页面上单击时添加了一些表单。
在这些新添加的元素中,我有必须使用 qTip 的图像。

我有这个:

$(document).ready(function () {    
$('.ttip').qtip({
content: $(this).attr('tooltip'),
show: 'click',
hide: 'click',
position: {
my: 'top right',
at: 'bottom center'
},
style: { classes: 'ui-tooltip-light' }
});
});

这适用于一开始就可见的元素。
所有使用 qTip 的元素都具有 runat="server" 属性。
但是当我使用 ttip 类添加新元素时,它不起作用。

探索我发现开头可见的元素具有属性:

data-hasqtip="6"

但动态添加的元素没有此属性。

如何解决这个问题?
如何让它以某种方式活起来?

根据答案更新

我已将其添加到使元素可见的代码后面:

// Button click handler that add new element to page
public void AddNewElement(Image image)
{
image.Visible = true;
image.ToolTip = "blah";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(),
"tmp",
@"<script type='text/javascript'>
$('.ttip').filter(function(){return !$(this).data('qtip')}).qtip(
content: $(this).attr('tooltip'),
show: 'click',
hide: 'click',
position: {
my: 'top right',
at: 'bottom center'
},
style: { classes: 'ui-tooltip-light' }
);
</script>",
false);
}

但是还是不行:(

最佳答案

添加新元素后,重新初始化 qTip 插件:

$('.ttip').filter(function(){return !$(this).data('qtip')}).qtip(...);

关于javascript - qTip 和动态添加元素问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20213202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com