21,891
社区成员
发帖
与我相关
我的任务
分享
<!--jquery -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
data_handle();
});
function data_handle(){
/*
* 转换为大写
* $('#x').val() 取值
* $('#x').val().toUpperCase() 转大写
* $('#x').val($(this).val().toUpperCase()) 赋值
*/
//alert($('#x').val().toUpperCase()); //debug
$('#x').val($('#x').val().toUpperCase());
var fen="fen"+i;
//提交url
var url = 'getdata.php';
//ajax的post提交
$.post(url,function(data){
//赋值
//alert(data); //debug
$('#fen').val(data);
}
);
}
</script>
<input type="text" value="asd" id="x" />
<input type="text" value="123" id="fen" />
<?php
include_once("conn.php");
$resault=mysql_query("SELECT * FROM ... WHERE `filed`='js里的value_1' LIMIT 1",$link)or die(...);
$date=mysql_fetch_array($resault);
$value_2=$data[5];
echo $value_2;
//页面打印的内容即为上面ajax获取的data
?>
function initAjax(){
var ajax = false;
try{
ajax = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
ajax = false;
}
}
if(!ajax && typeof XMLHttpRequest != 'undefined'){
ajax = new XMLHttpRequest();
}
return ajax;
}
function data_handle(x){
var value_1=document.getElementById(x).value;
value_1=value_1.toUpperCase();
document.getElementById(x).value=value_1;
var fen="fen"+i;//这个i是哪来的
var ajax = initAjax();
ajax.open("post","getdata.php",true);
ajax.onreadystatechange=function(){
if(ajax.readyState==4 && ajax.status==200){
document.getElementById(fen).value
=decodeURIComponent(ajax.responseText);
}
}
ajax.send(null);
}
getdata.php页面:
<?php
include_once("conn.php");
$resault=mysql_query("SELECT * FROM ... WHERE `filed`='js里的value_1' LIMIT 1",$link)or die(...);
$date=mysql_fetch_array($resault);
$value_2=$data[5];
echo $value_2;
?>