2010-03-08 65 views
0

我使用ajax從外部網站獲取網頁內容,但現在我想要一個提取已經自動填充的特定輸入字段值的函數。如何使用JavaScript從外部網頁提取特定輸入字段值

的網頁內容是這樣的:

......... 
<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"> 
......... 

我只想要得到的fullname值,可能與一些JavaScript正則表達式,或者一些jQuery的DOM解析器,我知道我可以用PHP很容易做,但我想用Javascript或jQuery。

注意:此輸入不在我的頁面託管,他們只是從其他網站通過Ajax拉。

感謝

回答

2

使用jQuery find方法類似$(response).find('#fullname').val()。這裏指的jQuery find文檔

1

jQuery的救援:

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()); 

編輯:Example at jsbin.com

相關問題