当前位置:编程学习 > C#/ASP.NET >>

document.form1.action=""疑问

请问各位大虾,能不能做到 A界面提交B页面的form到C页面。。。为什么总是提示“不是对象或为空”的js错误。。

如:A页面的提交按钮btnTest,B页面得表单myForm。。。要提交到C页面。。

document.myForm.action="C.aspx"

这样一直报对象为空的错误。。why??
--------------------编程问答-------------------- document.getElementById("myForm").action = "" --------------------编程问答--------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="gacwebdemo._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" OnClientClick="document.getElementById('form1').action = 'http://www.baidu.com';" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

--------------------编程问答--------------------
引用 2 楼 ihandler 的回复:
HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="gacwebdemo._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.……

你这是表单和提交按钮同一个页面啊。。如果表单是另外一个页面的呢?那怎么办。。 --------------------编程问答-------------------- 到javascript论坛问问,那里更专业。

另外,不要使用过去ie的专用语法,要使用标准的写法。 --------------------编程问答-------------------- Server.Transfer("")
通过<%@ PreviousPageType VirtualPath="~/a.aspx" %> 实现跨页提交 --------------------编程问答-------------------- ocument.getElementById所有浏览器都能用 --------------------编程问答-------------------- 正常情况下A页的按钮怎么能让B页的FORM提交呢.

除非你把B页用iframe方式放在A中,A用JS控制B提交.

或者A页是由B页动态打开的一个子页面,如通过<a href="a.html"></a>在B页中打开A页,
或者通过window.open("a.html","")
这样A可以通过parent或opener对象用JS来提交B

当然,B提交到C那没任何问题.
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,