变更表单的action属性 [英] Change form's action attribute

查看:140
本文介绍了变更表单的action属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我必须在这里失去了一些东西,因为这应该是非常简单的,但它不工作...

Okay, I must be missing something here because this should be extremely simple, yet it doesn't work...

我有一个格式我的网页上有一个空的动作属性(行动= #)。当页面准备好了,我想改变动作属性到别的东西。我的code是非常简单的:

I have a form on my page with an empty action attribute (action="#"). When the page is ready, I want to change the action attribute to something else. My code is very simple:

HTML

<form action="#" method="post" id="register"></form>​

jQuery的:

jQuery:

$("#register").attr("action", "http://www.test.com");​

即使在测试拨弄,这是行不通的!查看结果帧的源,你会看到动作属性仍是值

Even in a test fiddle, it doesn't work! View the source of the Result frame and you'll see the value of the action attribute is still #.

我要去哪里错了??

推荐答案

它的工作,你是不是正确的测试。查看源将告诉你什么来源看着被加载页面时像后,不是的jQuery进行修改。如果您警报()动作值后,被提取使用jQuery,你会看到新的值:

It does work, you aren't testing it properly. Viewing source will show you what the source looked like when the page was loaded, not after it as modified by jQuery. If you alert() action value after it is fetched with jQuery, you will see the new value:

alert($("#register").attr("action"));

这也是一个好主意,以确保所做的任何更改,为此,你可以使用之前的DOM加载就绪()

$(document).ready(function(){ /* your code */ });

退房: http://jsfiddle.net/wvYjs/2/

这篇关于变更表单的action属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆