0

有人可以帮忙吗?我有一个带有 asp.net 框架的网页——该框架显示了 html 文档的内容。当有人点击 html 文档中的链接时,我需要在同一页面的另一个框架中显示一些内容。

所以,问题是,下面的“myTag”应该是什么......

eg //这是我的html文件的内容`

<p>to be or not to be, <myTag>that</myTag>  is the question</p>

无论“myTag”是什么(可能是一段 javascript?不知道),它应该能够在服务器上触发一个事件,这样我就可以向页面上的另一个框架发送更多文本

有任何想法吗?

谢谢..

4

2 回答 2

1

我要做的第一件事是给另一个框架一个 ID 或某种方式,以便使用 javascript 轻松访问它。然后在您的 iframe 中,您可以执行以下操作:

var other_frame_document = window.parent.document.getElementById('other_frame').contentWindow.document;
// example 1: set the HTML of the other frame from a string.
// this is usually a bad idea because of XSS.
other_frame_document.body.innerHTML = '<b>aloha</b>';

// example 2: better way is to manipulate the DOM in the other iframe
var elm = other_frame_document.createElement('b');
elm.appendChild(other_frame_document.createTextNode('aloha'));
other_frame_document.body.appendChild(elm);
于 2012-05-31T14:56:19.830 回答
0

这是触发动作的一种方式。

或者您可以在 DOM 加载时使用 jQuery(或其他库)绑定操作,如下所示:

jQuery("#myTagId").bind("click", function() { ... });

这将导致在单击元素时触发事件。

然后,您可以使用 ajax 调用服务器来更新其他框架。

于 2012-05-31T14:55:36.867 回答