1

Using Tumult Hype, I built a date range selector, and I'm currently adding the functionality to it... however, Hype likes to put it's HTML snippets into iFrames.

I'm having trouble targeting an input field that is in an iframe, so I can populate it with the current year. I'm also not able to give the iframe an ID either within Hype.

The path to the input is like this:

#startyear > div > #start-year-text > iframe > html > body > input#start-year-placeholder

obviously, using jQuery, this doesn't work:

$("#start-year-placeholder").attr("placeholder","1973");

neither does this:

$("#startyear > div > #start-year-text > iframe > html > body > input#start-year-placeholder").attr("placeholder","1973");

From the web page linked below, you'll see the first date range selectors. I'm trying to set the placeholder text attribute of the first year input dynamically. Right now it is hardcoded.

You can see the full HTML here: http://aceroinc.ca/question/footer.html

4

1 回答 1

2

你可以这样定位它:

$('iframe').contents().find('input#start-year-placeholder')

注意:这适用于您的页面,但通常如果您要添加更多 iframe,您可能需要调整iframe选择器。此外,这仅适用于 iframe 与父页面的域相同。

于 2013-11-11T04:33:13.633 回答