如何使用jQuery从iframe中的div获取文本
我有一个页面,该页面使用iframe进行ajax样式的文件上传.上传完成后,我正在将div写入iframe,其状态为是否上传了文件. iframe不可见,我正在将其用作表单的目标.一切正常,除了我无法弄清楚如何使用jquery在div中获取文本.我的iframe的ID为upload_target,而iframe中的div的ID为uploadStatus.我以为以下方法会奏效,但不会奏效.有人知道我该怎么做吗?谢谢.
I have a page that uses an iframe to do an ajax style file upload. When the upload completes I'm writing a div to the iframe with the status of whether their file was uploaded or not. The iframe is not visible and I'm using as a target for the form. It all works fine except that I can't figure out how to use jquery to get the text within the div. My iframe has an id of upload_target and the div in the iframe has the id of uploadStatus. I thought the following would work but it doesn't. Does anyone know how I can do this? Thanks.
$("#upload_target").load(function () {
alert($("#upload_target> #uploadStatus").text());
});
确保您的iframe
的name
属性也设置为upload_target
,然后使用
Make sure your iframe
has its name
attribute set to upload_target
as well, and then use
alert($("#uploadStatus", frames['upload_target'].document).text());