2012-11-02 82 views
0
<p><input name="form[ip]" id="ip" class="ip" type="text" value="Enter IP here" /> 
</p>    
<p><input type="submit" value="Submit" /></p> ​ 


var currentPageURL = "http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true"; 
var ip = getMeasurementsFromUrl(currentPageURL) 

alert(ip); 

function getMeasurementsFromUrl(ip) 
{ 

var ipMeasurmentString = ip.substring(ip.lastIndexOf('ip=')+3); 

ipMeasurmentString =ipMeasurmentString.replace("&position=true",""); 
ipMeasurmentString =ipMeasurmentString.replace(",","."); 
ipMeasurmentString =ipMeasurmentString.replace("/","."); 
ipMeasurmentString =ipMeasurmentString.replace("-","."); 
ipMeasurmentString =ipMeasurmentString.replace(",","."); 
ipMeasurmentString =ipMeasurmentString.replace("/","."); 
ipMeasurmentString =ipMeasurmentString.replace("-","."); 
ipMeasurmentString = 
return ipMeasurmentString; 
} 

我想,所以它讀取輸入的IP編輯webaddress,到目前爲止,我已經得到了它的當前閱讀的IP的地址,並有一個表格輸入ip。輸入字符串轉換成URL - 使用HTML表單和javascript

此外,如果任何人有任何提示如何製造更多的IP格式將有所幫助。

http://jsfiddle.net/mqWGm/8/

+0

是currentPageURL串固定的嗎?還是它改變了? – Greezer

+0

我試圖得到它,所以輸入的IP可以放進currentPageURL,然後.php將在html中輸出。 – WherEmEweeD

+0

嗨Greezer,它從輸入表單變爲ip – WherEmEweeD

回答

0

如果IP ADRES不會改變,你可以使用:

element = document.getElementById("ip"); 
var newstring = ipMeasurmentString.replace("ip=12.215.42.19&",element.value); 

,如果它改變你可以嘗試:

var part = str.split("ip="); 
var newstring = part[0] + "ip=" + element.value + "&position=true"; //part[0] = text before the ip=