通过id javascript填充文本字段
filling in textfield by id javascript
我有代码,有一个文本字段和一个按钮在javascript。当用户点击按钮时,它会打开一个网站搜索页面的新窗口。我想做的是通过使用它的id来填充搜索字段,然后激活网站的搜索按钮。我似乎没有能够得到传递到外部网站的文本字段的文本,但这是我所拥有的。
<script type="text/javascript">// <![CDATA[
function mySearch()
{
popupWindow = window.open(
'http://www.websitehere.com','popUpWindow','height=768,width=1024,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
popupWindow.focus();
popupWindow.searchpath1 = 'test value';
}
// ]]></script>
<center><form><input name="searchTxt" type="text" /><br /> <input onclick="mySearch()" value="Search" type="button" /></form></center>
textBoxId将是新打开窗口的搜索文本框的id。
如果有什么不明白的地方,请告诉我。
下面是外部站点文本框的源代码:
<input title="Search Term" type="text" name="searchpath1" id="searchpath1" maxlength="255" size="25" style="width: 300px;" value=""/>
试试
popupWindow.document.getElementById('textBoxId').value = 'test value';
不是popupWindow.textBoxId = 'test value';
您需要获取输入文本DOM元素'textBoxId'并设置该获得元素的'value'属性。
这行不对
popupWindow.textBoxId = 'test value';
用以下几行替换:
var targetTextField = popupWindow.document.getElementById('textBoxId');
targetTextField.value = "test value";
在这里,我重写了完整的函数定义来评估建议的解决方案。尝试一下,让我们知道它是如何工作的![] s
function mySearch()
{
popupWindow = window.open('file:///tmp/form.html','popUpWindow','height=768,width=1024,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no,status=yes')
if (window.focus())
popupWindow.focus();
var targetTextField = popupWindow.document.getElementById('textBoxId');
targetTextField.value = 'test value';
targetTextField.focus();
}
相关文章:
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 当设置addFromAutocompleteOnly时,剩余文本将保留在输入字段中
- 使用jquery将输入字段转换为文本
- 如何从查询字符串中的输入字段发回文本
- 表单输入字段随着溢出的文本而增长
- 使用单个文本框向多个字段添加严格搜索
- 使用javascript提交表单并从字段/单选框/复选框/文本区域获取数据
- 使用jQuery的输入字段文本换行
- 向使用jQuery加载DOM后添加的字段添加不受限制的文本输入DatePickers
- 当用户单击按钮(在光标位置)时,在输入字段中添加一个文本字符串
- 如何根据文本长度立即显示和隐藏字段?-JQuery
- 如何使文本、数字和日期html输入字段以一致的方式支持Ctrl+Z(撤消)
- 模拟文本输入字段上的退格键
- 输入字段中的可持续文本
- 未获取文本输入字段的值
- 没有文本安全性的密码字段
- 将禁用的输出字段更改为带前缀的文本
- 为什么 react 将输入[类型=“文本”] 字段设为只读,除非我提供 onChange 回调
- 使用SAPUI5中的“文本”字段显示正确的“日期”
- Kendo,如何将MVVM文本:字段绑定到远程DataSource