Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iframe中的asp.net javascript getelementbyid_Javascript_Jquery_Html_Asp.net_Iframe - Fatal编程技术网

iframe中的asp.net javascript getelementbyid

iframe中的asp.net javascript getelementbyid,javascript,jquery,html,asp.net,iframe,Javascript,Jquery,Html,Asp.net,Iframe,我正在尝试在iframe中填充我的表单。我需要在文本框中输入一个值,然后从下拉菜单中选择一个值 网络表单1 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="admin-lte/js/app.min.js"></script

我正在尝试在iframe中填充我的表单。我需要在文本框中输入一个值,然后从下拉菜单中选择一个值

网络表单1

<!DOCTYPE html>    
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script src="admin-lte/js/app.min.js"></script>
    <script src="Scripts/jquery-2.1.3.min.js"></script>

</head>
<body>
    <style type="text/css">
    body {scrolling:no;
}
    iframe {position:absolute;
    z-index:1;
    top:0px;
    left:0px;
}
</style>
    <form id="form1" runat="server">

    <iframe id="frame1" src="WebForm4.aspx" width="100%" height="100%" frameborder="0">
</iframe>

    <script>
        function getElementWithinIframe() {


            var iframe = document.getElementById('frame1');
            var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;

            var quantity = innerDoc.getElementById("txtQuantity");
            quantity.value = "5";

            var submit = innerDoc.getElementById("btnQuantity");
            submit.click();
        }
    </script>

    </form>
</body>
</html>
网络表单4

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:DropDownList ID="ddlProd" runat="server">
            <asp:ListItem>Product1</asp:ListItem>
            <asp:ListItem>Product2</asp:ListItem>
            <asp:ListItem>Product3</asp:ListItem>
            <asp:ListItem>Product4</asp:ListItem>
            <asp:ListItem>Product5</asp:ListItem>

        </asp:DropDownList>
        <asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>

        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />

    </div>
    </form>
</body>
</html>
这不管用。我错过了什么

我看过多篇文章,但我想我没看懂

感谢您的帮助

-
感谢您在父级中的javascript中使用BtQuentiy,而WebForm4.aspx中的按钮的ID为btnSubmit。因此,将脚本更改为:

var submit = innerDoc.getElementById("btnSubmit");
然后在某个地方调用该函数,可以单击按钮,也可以加载页面

<input type="button" onclick="getElementWithinIframe()" value="ClickMe">

<script>
    $(document).ready(function () {
        setTimeout(function () { getElementWithinIframe(); }, 250);
    });
</script>

好吧,那是我的错误。但它仍然不起作用。正如你所说,我改变了剧本。TextboxtxtQuantity未填充。它在我的测试环境中填充。你是否清除了WebForm4背后代码中txtQuantity的内容,可能是因为你也在做一篇表单文章,而且你必须在某个地方调用GetElementWithinFrame。window.onload=GetElementWithinFrame;函数GetElementWithinFrame{这不起作用。