小弟做Web不久,接手维护一个别人的Web工程,写新的小功能时候遇上问题.
有个类似如下的from:

         <table>
<tr>
<input type="button" value="Test" onclick="Print('hahaform')"/>
</tr>
<tr>
<form id="hahaform" action="haha">
<input name="action" value="heihei" type="hidden"/>
</form>
   </tr>
</table>
我要在按下按钮后在JS里面操作form的action属性,但是原来代码的结构,居然要在每个form里面添加一个名字叫做action的隐藏的控件,来提交一些消息,这个name是action的input我还不能删,但是我js就没办法取到form的action属性来操作了.请教各位大侠,是不是就没有办法了?不能用js来操作这个form的action属性了?

解决方案 »

  1.   

    document.getElementId("hahaform")可以获得这个form
    document.hahaform.action=""    直接赋值
    <form id="hahaform" name="hahaform" action="haha">
      

  2.   

    按照1楼的方法不行阿,写个简单的测试脚本<html>
    <head>
    <script type="text/javascript">
    function Print(formname)
    {
    var form = document.getElementById(formname);
    alert(form.action);
    }
    </script>
    </head><body>
    <table>
    <tr>
    <input type="button" value="Test" onclick="Print('hahaform')"/>
    </tr>
    <tr>
    <form id="hahaform" action="haha">
    <input name="action" value="heihei" type="hidden"/>
    </form>
       </tr>
    </table>
    </body>
    </html>
    我就是想在按下按钮的时候显示from的action属性haha,而不是那个input的控件对象.
      

  3.   

    function Print()
            {
                var form = document.getElementById("hahaform");
                alert(form.action);
            }
      

  4.   

    你这种写法很奇怪 呵呵   你在form里 加个name
    <form id="hahaform" action="haha" name="hahaform">
    然后
    function Print()
            {
                alert(document.hahaform.action);
            }
      

  5.   

    alert(form.getAttribute("action").value);332304896我们可以交流,以后有什么问题找我啊
      

  6.   

    回wenchao_222
    你得方法还是不行哦,alert出来的还是那个input的action.另外,这个工程的框架不是我搭的,去掉那个名字叫做action的form的话,代码结构也要改动,还TMD是基类的,不晓得他还有多少页面要用到这个傻东西阿.55555,我也很委屈.回cs_zhanshen
    你得和wenchao_222效果一样,都不行哦.呵呵我要的效果是打印出form的action属性,就是那个haha字符串.谢谢各位关注,我怀疑他这么设计了form以后,根本没办法在js里面获得form的这个action属性了,看来我得想别的办法了.贴子明天结,没有满意答案的话,就只把分送给你们二位了,谢谢.
      

  7.   

    cs_zhanshen大侠帮我搞定了方法是
    alert(form.attributes('action').value);多谢!!!