本文介绍了如何从iframe下拉所选文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe,它以模态打开。内容存在于iframe.jsp中。现在iframe包含一个下拉列表。在更改下拉列表时,我将调用另一个窗口。但是,如果用户在下拉选项中选择了选项:camRip,则不会调用该窗口。

I have an iframe, which opens up in a modal. The contents are present in iframe.jsp. Now the iframe contains a drop down. On change of drop down i will call another window. However, if the user selects the option : camRip in the drop down options, then that window will not be called.

我的更改代码如下所示:

My code for on change looks like this :

<select id="hamStan"  onchange = "callWindow('<%=URL %>');">

我的更改是这样的:

function callWindow(URL) {
var selectedByUser = document.getElementById("hamStan");
var strUserText = selectedByUser.options[selectedByUser.selectedIndex].text;
if(strUserText!="camRip ")
{
var windowName = "popUp";
var windowSizeArray = [ "width=740,height=400,top=10,left=50,toolbar=1,location=1,directories=0,status=0,menuBar=1,scrollBars=1,resizable=1"];
window.open(URL,windowName,windowSizeArray);
}
}

但问题是selectedByUser即将出现。我哪里错了?请帮助。如何从模态iframe.jsp获取用户选择的下拉值?

But the problem is selectedByUser is coming up as null. Where am i going wrong ? Kindly help . How do i get the drop down user selected value on change from the modal iframe.jsp ?

推荐答案

经过大量研究后我终于找到了解决方案。

After a lot of research i finally found the solution .

这就是我的结果:

function callWindow(URL) {
var iframe = window.parent.parent.document.getElementById('myIframe');
var iwin= iframe.contentWindow || iframe.contentDocument.defaultView;
var selectedByUser  = iwin.document.getElementById('hamStan');
var strUserText = selectedByUser.options[selectedByUser.selectedIndex].text;
if(strUserText!="camRip ")
{
var windowName = "popUp";
var windowSizeArray = [ "width=740,height=400,top=10,left=50,toolbar=1,location=1,directories=0,status=0,menuBar=1,scrollBars=1,resizable=1"];
window.open(URL,windowName,windowSizeArray);
}
}

请确保您正确访问iframe- id否则变量iframe会给你一个类型错误。希望它能帮助他人。

Be sure here that you are correctly accessing the iframe-id otherwise variable iframe will give you a type error. Hope it helps others.

这篇关于如何从iframe下拉所选文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:21