简体   繁体   English

如何在使用javascript设置链接的html中添加锚标记?

[英]How can I add in anchor tags to html where links are set with javascript?

I have an old page where all the links on the page are set with javascript and no anchor tags are used on the site. 我有一个旧页面,该页面上的所有链接均使用javascript设置,并且网站上未使用锚标签。

I need to rebuild these pages but need the anchor text to be added to the html. 我需要重建这些页面,但需要将锚文本添加到html中。 Currently spans with IDs are used to tell the javascript where to create the links. 当前带有ID的跨度用于告诉javascript在哪里创建链接。 For example: 例如:

<span id="sleeponit_hypertext" style="cursor:pointer"><font face="Arial"><span 
    style=" font-size:15px"><b><u>National Aeronautics 
    and Space Administration</u></b></span> 

Would be used by the javascript to set National Aeronautics and Space Administration as a link (using findobject and actionevents to set the location of where onclick should take the user). javascript将使用它来将国家航空航天局设置为链接(使用findobject和actionevents设置onclick会将用户带到的位置)。

Is there anyway I can automatically have the anchor tags? 无论如何,我可以自动获得锚标签吗? Any ideas on how to approach the problem would be helpful. 关于如何解决该问题的任何想法都会有所帮助。

EDIT: To help clarify, the javascript functions that sets the link are as follows: 编辑:为帮助澄清,设置链接的javascript函数如下:

    FindObject( "sleeponit_hypertext").onmousedown = function(){ sleeponit_hypertext_MouseDown();  };
FindObject( "sleeponit_hypertext").onmouseup = function(){ sleeponit_hypertext_MouseUp(); };
 FindObject( "sleeponit_hypertext").onmousemove = function(){ sleeponit_hypertext_MoveIn(); };
 FindObject( "sleeponit_hypertext").onmouseout = function(){ sleeponit_hypertext_MoveOut();  };
 actions.sleeponit_action43 = new SetCursorAction( "pointer");
 actions.sleeponit_action44 = new SetCursorAction( "default");
 actions.sleeponit_action55 = new PageAction( "indivlearning.html")

PageAction function just loads the window with the filename passed through (in this case indivlearning.html). PageAction函数仅使用传递的文件名加载窗口(在本例中为indivlearning.html)。

parent.loadPage(this.m_PageName)

Where this.m_PageName is what was passed to PageAction. 其中this.m_PageName是传递给PageAction的内容。

I'd love to fire the PageActions with the corresponding links on page load with the added anchor tags. 我很乐意使用添加的定位标记在页面加载时触发具有相应链接的PageActions。

(Edited) (编辑)的

OK, I understand better now. 好,我现在更好了。

I would probably write some jQuery code that iterates through the span[@id] elements; 我可能会写一些迭代span [@id]元素的jQuery代码; have it programatically fire the click event on each one; 以编程方式在每个事件上触发click事件; but modify the js routine that says newURL = ....; window.location = newURL; 但是修改说newURL = ....; window.location = newURL;的js例程newURL = ....; window.location = newURL; newURL = ....; window.location = newURL; such that instead of changing window.location , it changes the DOM tree under that span, replacing the inner span with 这样,它无需更改window.location ,而是更改该范围下的DOM树,将内部范围替换为

<a href="newURL">[text content of the <b><u>]</a>

Once the DOM tree is transformed, you can have it spit out the resulting HTML. 转换DOM树后,就可以吐出结果HTML。

The above description is sketchy... I didn't want to elaborate unnecessarily. 上面的描述是粗略的...我不想赘述。 If you have questions, fire away. 如有疑问,请开除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM