简体   繁体   中英

How do I set the value of an input field inside an iframe with jQuery?

I have a form inside an iframe that needs to be manipulated from the main frame.

The iframe is viewed in a pop-over when a button is clicked in the main frame. It then contains a upload form with a hidden field called dir.

I want to set the hidden field before showing the form. I tried:

$('#upload_iframe').contents().find('#dir').val(dir);

... which runs. And the new value can be printed with alert() in the main frame. However, the iframe doesn't change it's value. Can you help me figure out why?

Thank you!

I don't believe this is possible in a single line of jQuery. The solution I can think of is somewhat more convoluted.

The IFrame will have a source page (say, test.aspx, for example). To get a text box on that page to be posted you can set the URL to include the text:

$("#upload_iframe").attr("src", "text.aspx?dir=YourDirTextHere");

Then in your server side code you would pick this up off the querystring.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM