在 iframe 中设置输入文本并提交 [英] Set input text inside iframe and submit

查看:26
本文介绍了在 iframe 中设置输入文本并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过将值从一个传递到另一个来将两个 Web 服务粘合在一起,不幸的是,没有 API 或明确的方法来破解搜索查询,因此我需要在 iframe 内设置输入的值.

I'm trying to glue together two web services by passing a value from one to the other, unfortunately there's no API or clear way of hacking up the search query so I need to set the value of a input inside an iframe.

这是可怕的 iframe 的标记.

Here's the markup for the horrible iframe.

<form id="searchForm" method="post" action="/search/initialSearch">         
  <fieldset class="searchFields">
    <input type="text" name="searchTerm" value=""/>
    <input type="submit" value="Find stops"/>
  </fieldset>
</form>

我需要设置 searchTerm 文本,然后提交表单.

I need to set the searchTerm text and then submit the form.

注意:这是移动设备,所以我更喜欢一个非常轻量级的解决方案

推荐答案

是不是就这么简单:

myframe.document.getElementById("searchForm").searchTerm.value = 'hello';
myframe.document.getElementById("searchForm").submit();

确保您的脚本在 iframe 加载后运行.您的 iframe 标签有一个 onload 事件,您可以使用它来确定何时加载框架内的页面.

Make sure your script runs AFTER the iframe is loaded. Your iframe tag has an onload event that you can use to determine when the page within the frame is loaded.

<iframe src="formPage.html" onload="loaded()" name="myframe" />

这篇关于在 iframe 中设置输入文本并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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