我正在开发一项功能,如果您单击简介链接,它将在预览窗口中显示完整的描述;很像 Google 等搜索引擎中的搜索结果预览。
我需要将完整的描述文本和事件传递给处理函数,以便该函数知道要显示什么以及在哪里显示(在简介下)。
我的问题是我应该将什么传递给该函数。目前我有以下但不起作用:
<a href="javascript:DisplayFullDescription('blah blah description goes here');">blurb text here</a>
function javascript:DisplayFullDescription(e, fullText){
//find out mouse click position
//display a preview window (div) with description there
}
最佳答案
如果您个人不使用 HTML5,我会使用 display:none
为全文创建一个隐藏元素,我会将其作为数据分配给每个适用的元素,并使用该信息点击
<a class="clickable" href="#">blurb text here<span style="display:none">blah blah description goes here</span></a>
$('a.clickable').each(function() {
$(this).data('fulltext',$(this).find('span').remove().text());
}).click(function(event) {
event.preventDefault();
$('body').append('<div>'+$(this).data('fulltext')+'</div>');
})
关于当有另一个参数时Javascript事件访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12076742/