开发者

How to extract a specific input field value from external webpage using Javascript

开发者 https://www.devze.com 2022-12-22 00:42 出处:网络
i get the webpage content from an external website using ajax but now i want a function which extract a specific input开发者_如何转开发 field value which is already autofilled.

i get the webpage content from an external website using ajax but now i want a function which extract a specific input开发者_如何转开发 field value which is already autofilled.

the webpage content is like this:

.........
<input name="fullname" id="fullname" size="20" value="David Smith" type="text">
<input name="age" id="age" size="2" value="32" type="text">
<input name="income" id="income" size="20" value="22000$" type="text">
.........

I only want to get the value of fullname, maybe with some javascript regex, or some jQuery dom parser, i know i can do it easily with php but i want it using Javascript or jQuery.

Note: this inputs are not hosted in my page, they are just pulled from other website through Ajax.

Thanks


Use jQuery find method like $(response).find('#fullname').val(). Refer jQuery find Documentation here


jQuery to the rescue:

var body = '<div><input name="fullname" id="fullname" size="20" value="David Smith" type="text"><input name="age" id="age" size="2" value="32" type="text"><input name="income" id="income" size="20" value="22000$" type="text"></div>';
var selector = 'input[name=fullname]';
alert($(selector, body).val());

EDIT: Example at jsbin.com.

0

精彩评论

暂无评论...
验证码 换一张
取 消