如何使用jQuery从iframe中的div获取文本 [英] how to get text from a div in an iframe with jquery

查看:131
本文介绍了如何使用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());
 });

推荐答案

确保您的iframename属性也设置为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());

这篇关于如何使用jQuery从iframe中的div获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆