[英]How do you click text that's inside a hyperlink so you can drag and highlight it?
If you have a paragraph of normal text, you can click anywhere inside the text and drag your mouse to highlight it.如果您有一段普通文本,您可以单击文本内的任意位置并拖动鼠标以突出显示它。 However, if the text is inside an anchor/link tag, it won't allow you to click and drag -- the link catches the mouse and prevents it from happening.但是,如果文本位于锚点/链接标签内,则不允许您单击和拖动 - 链接会抓住鼠标并阻止它发生。
To see what I mean, find a text link on this page and try to click inside it and drag to select it.要了解我的意思,请在此页面上找到一个文本链接,然后尝试在其中单击并拖动到 select 它。 It won't let you -- you'll have to click outside the link and drag around it.它不会让你 - 你必须点击链接外部并拖动它。
What do you need to do in JavaScript/JQuery to temporarily disable the link long enough for you to drag and highlight it?您需要在 JavaScript/JQuery 中做些什么来暂时禁用链接足够长的时间以便您拖动和突出显示它?
The reason I can't just start outside the link is because every word in the paragraph is within a hyperlink -- it's a video transcript and each link is synced to a segment in the video.我不能只在链接之外开始的原因是因为段落中的每个单词都在一个超链接内——它是一个视频脚本,每个链接都同步到视频中的一个片段。
My first thought was to do something like this:我的第一个想法是做这样的事情:
$("a").each(function() {
$(this).replaceWith("<span class='link' data-href='" + $(this).attr("href") + "'>" + $(this).text() + "</span>");
});
$(".link").click(function() {
window.location = $(this).data("href");
});
However, there may be a much better way of doing this.但是,可能有更好的方法来做到这一点。 The code above converts all a
elements into span
elements, keeping the href
attribute value, and then makes the span
elements with class "link" function as links.上面的代码将所有a
元素转换为span
元素,保留href
属性值,然后将span
元素与class“链接”function作为链接。 You could style the span
elements to look like a
elements currently do on your page.您可以设置span
元素的样式,使其看起来像页面上当前a
元素。
You could try this solution , loading the original text into variables and then restore them.您可以尝试此解决方案,将原始文本加载到变量中,然后恢复它们。
But that seems too messy.但这似乎太混乱了。 Sometimes a simpler solution is better.有时更简单的解决方案会更好。
Why not have two paragraphs and set visibiltiy='hidden' when the user clicks on a button to hide the paragraph with links and show the paragraph without links?当用户单击按钮以隐藏带有链接的段落并显示不带链接的段落时,为什么不设置两个段落并设置 visibiltiy='hidden'?
Page weight doesn't seem to be an issue, since you're anyway loading video.页面重量似乎不是问题,因为无论如何您都在加载视频。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.