我有兩個文本字段,無論用戶在第一個文本字段中輸入什麼字段,Ajax都會顯示第二個字段。我需要使用循環有多行,每一行都有自己的價值。 HTML具有特定值的多個文本字段行使用Ajax
<form style="text-align:center" method="post" action="" name="form1">
<?php for($x=0; $x<4; $x++){ ?>
<input type="text" size="30" id="country" onChange="getCurrencyCode('find_ccode.php?country='+this.value)" />
<input type="text" name="cur_code" id="cur_code" ></p>
阿賈克斯
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getCurrencyCode(strURL)
{
var req = getXMLHTTP();
if (req)
{
req.onreadystatechange = function()
{
if (req.readyState == 4)
{
if (req.status == 200)
{
document.getElementById('cur_code').value=req.responseText;
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
腓
$country=$_REQUEST['country'];
echo $country;
請幫我一把。
您是否知道後的文本輸入的內容,改變了「的onChange」事件將不會發出?當輸入失去焦點時它會閃光。 – Exander 2012-04-23 09:11:39
他可以使用'setInterval'來檢查一次,如果當前更改的字段的值確實發生了變化,則啓動該調用。 – Eugene 2012-04-23 09:21:26