用于触发事件的Html

时间:2012-05-31 14:42:32

标签: javascript

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

所以,问题是,'myTag'在下面应该是什么......

e.g。 //这是我的html文件的内容

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

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

有什么想法吗?

感谢..

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:0)

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

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

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

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

然后,您可以使用ajax调用服务器来更新另一帧。

相关问题