javascript 从序列化字符串中获取值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16776858/
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
get a value from a serialized string
提问by pnm123
There is a form, and on submit, I convert it to a serialized string to in order to submit the form via ajax.
有一个表单,在提交时,我将其转换为序列化的字符串,以便通过 ajax 提交表单。
var data = $$.serialize();
Now there is an input field named 'title' and I want to get its value to show a message. So I am looking for a method to do just that. I've tried;
现在有一个名为“title”的输入字段,我想获取其值以显示消息。所以我正在寻找一种方法来做到这一点。我试过了;
alert(data.name);
But found out it's not the method.
但发现这不是方法。
UPDATE
更新
Here is the fiddle: http://jsfiddle.net/wHBYK/
这是小提琴:http: //jsfiddle.net/wHBYK/
回答by Niccolò Campolungo
You don't need jQuery at all. Just do this:
你根本不需要 jQuery。只需这样做:
$('#frmEditTab').submit(function(e){
e.preventDefault();
var title = this.title; //get the input named "title" of the form
alert(title.value); //alerts the value of that input
});