如何禁用iframe中的文本框 [英] How do i disable a text box within an iframe

查看:114
本文介绍了如何禁用iframe中的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:一个叫做index.html的大型页面,一切都发生在这里。
索引有10个选项卡(jquery ui选项卡)。使用jquery ui的手风琴部件,每个选项卡现在平均有3-5个子类别(我被拒绝张贴图片作为垃圾邮件防止,但我希望你明白布局看起来像什么)。这里是问题开始的地方。 iframe驻留在所有这些,所以我在25-30个iframe与大约5-10文本字段在每个iframe。我想做的只是简单地启用/禁用这些文本字段。

The scenario: One big bulky page called index.html, everything happens here. Index has 10 tabs (jquery ui tabs). Using jquery ui's accordion widget, each tab now has, on average, 3-5 sub categories (I was denied posting a picture as spam prevention but I hope you understand what the layout looks like). Here's where the problem starts. An iframe resides in all of these, so I'm looking at 25-30 iframes with about 5-10 text fields in each iframe. What I want to do is just simply enable/disable these text fields.

很简单,我知道这可以通过以下方式完成:

Quite simply i know this can be done by:

$('input[type=text]').attr("disabled", "disabled");

$('input[type=text]').removeAttr("disabled")

索引上的按钮触发一个函数:

A button on index triggers a function:

 $(".frameClass").each(function () {
                console.log("i found a frame called " + this.name);
});

如何使所有输入文本字段的此连接在点击时启用?我甚至尝试在iframe中创建一个函数,并尝试从 .each()

How do I make this connection for all input text fields to be enabled on a click? I even tried creating a function within the iframe and tried calling it from within the .each()

this.unlockFields();

没有让我在任何地方,任何想法?

hasn't gotten me anywhere, any thoughts?

推荐答案

您必须使用 .contents()才能存取元素在iframe中,像这样:

You have to use .contents() to access the elements in the iframe, like so:

$(".frameClass").each(function () {
     $(this).contents().find('input[type=text]').attr('disabled', 'disabled');
});

它应该做你想要的,因为iframe包含同一域作为主页。

that should do what you want, given that the iframe contains a page that is on the same domain as the main page.

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

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