从包含表单的Object中提取值

时间:2016-04-25 12:43:36

标签: javascript jquery

我有一个包含表单的JavaScript对象。当我打印物体时它就像吼叫一样。

<form action=\"https://www.example.com/api/tty/1p0/user/pwc\" method=\"POST\" target=\"_self\" enctype=\"application/x-www-form-urlencoded\" >

<input type=\"hidden\" name=\"ppw_version\" value=\"TTR-1p0\" />
<input type=\"hidden\" name=\"custom_source\" value=\"98\" />
<input type=\"hidden\" name=\"resource_url_id\" value=\"xxx-xx-xxx-xxxx\" />
<input type=\"hidden\" name=\"lis_person_id\" value=\"xxxxxx\" />
<input type=\"hidden\" name=\"oauth_nonce\" value=\"xxxxxxx-xxxx-xxxx-xxxxx\" />
<input type=\"hidden\" name=\"oauth_timestamp\" value=\"1461584435\" />
<input type=\"hidden\" name=\"oauth_consumer_key\" value=\"xxxxx\" />
<input type=\"hidden\" name=\"oauth_signature_method\" value=\"HMAC-SHA1\" />
<input type=\"hidden\" name=\"oauth_version\" value=\"1.0\" />
<input type=\"hidden\" name=\"oauth_signature\" value=\"xxxxxxxxxxxxxxxxxxx=\" />
<input type=\"submit\" style=\"\" value=\"\" />

</form>

我想从该对象中提取“ppw_version”值并将其分配给变量。是否可以在Java Script中使用?

Data = "<form action=\"https://www.example.com/api/tty/1p0/user/pwc\" method=\"POST\" target=\"_self\" enctype=\"application/x-www-form-urlencoded\" ></form>"

从“数据”中我想提取“ppw_version” 感谢

2 个答案:

答案 0 :(得分:1)

使用jQuery

var $form = $("form");
var ppwVersion = $form.find("[name='ppw_version']").val();

答案 1 :(得分:0)

根据之前的回复,我觉得这可能会有所帮助:

var $form = $(Data); // If Data is a FORM object, then now $form is a jquery-wrapper around that object
var ppwVersion = $form.find("[name='ppw_version']").val();