jQuery jquery获取帖子操作网址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2550620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery getting post action url
提问by djburdick
I'm trying to access the post target action in a jquery function.
我正在尝试在 jquery 函数中访问 post 目标操作。
example:
例子:
<form action="/page/users" id="signup" method="post">
I'd like to access the "action" part - "/page/users" in this case.
在这种情况下,我想访问“操作”部分 - “/page/users”。
$('#signup').live("submit", function(event) {
// get this submitted action
}
Seems like I'm missing something very simple. I see the value in the dom but don't know where it's stored in jquery.
好像我错过了一些非常简单的东西。我看到 dom 中的值,但不知道它在 jquery 中的存储位置。
Thanks!
谢谢!
回答by Amy B
$('#signup').on("submit", function(event) {
$form = $(this); //wrap this in jQuery
alert('the action is: ' + $form.attr('action'));
});
回答by Vikram Biwal
Try this ocde;;
试试这个 ocde;;
var formAction = $("#signup").attr('action');
回答by Fereydoon Barikzehy
Clean and Simple:
干净简单:
$('#signup').submit(function(event) {
alert(this.action);
});