0
我試圖將一個變量傳遞給一個javascript函數,但我不確定發生了什麼,因爲我主要是一個PHP人。將變量傳遞給ajax函數
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(str){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById("emailconfirm").innerHTML= ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "Atest.php?Email="+str, true);
ajaxRequest.send(null);
}
//-->
</script>
形式
<form name='myForm'>
<input name="email" id="email"type="text" />
<input name="button" onclick="ajaxFunction(document.getElementById('email').value" type="button" />
</form>
我想能夠一次按鈕獲得點擊,電子郵件文本輸入將被傳遞給JavaScript函數。
爲什麼不直接傳入ID並在函數中進行查找?更乾淨。但是,當然,你可以通過任何你想要的功能。 –
你onclick屬性中的語法錯誤,缺少'''' – Musa
jQuery在3 ... 2 ... 1 – NicoSantangelo