jquery中獲得$.ajax()事件返回的值并添加事件的方法
更新時間:2010年04月15日 23:02:47 作者:
如果想獲得$.ajax()中返回的值,直接用在success:funciton(){return xx} 是不可以的,要想獲得xx的值,要在script中,使用全局變量。利用全局變量引出xx的值。
如果想獲得$.ajax()中返回的值,直接用在success:funciton(){return xx} 是不可以的,要想獲得xx的值,要在script中,使用全局變量。利用全局變量引出xx的值。
jquery 取得$.ajax事件中的返回值,并添加事件
<html>
<head>
<title>測試JQUERY提交動態(tài)文本</title>
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
$(function(){ //引用的jquery文件我就不上傳了,大家應(yīng)該都有的。
$("#a1").clone().appendTo("#ap");
var a=""; //定義全局變量 a;
txtadd();
alert(a); //測試全局變量是否有值;
$("#tall").blur(function(){ alert("測試一下"); }); //添加一個從同步事件里返回文本框的blur事件
$("#a1").blur(function(){ alert("本頁面事件!"); });//注意,clone出來的a1文本框不具有blur事件;
function txtadd(){
$.ajax({
async:false, //使用同步請求,因為異步請求不能將返回值傳給全局變量;
type:"post",
url:"autotxt.php",
data:{txtid1:1,txtid2:2},
beforeSend:function(){$("#tt").html("數(shù)據(jù)加載中。。。")},
success:function(data){$("#tt").html(decodeURI(data)); //autotxt.php返回值<input name='tall' id='tall' value='dc' maxlength='6'/>;
a=$("#tall").val(); //將返回值做處理給全局變量
}
});
}
})
</script>
</head>
<body>
<form action="autotxt.php" method="post">
<div id="tt"></div>
<div id="ap"></div>
<input type="text" id="a1" name="a1" value="測試" />
<input type="hidden" id="ok" name="ok" value="ok" />
<input type="submit" value="確定" />
</form>
</body>
</html>
jquery 取得$.ajax事件中的返回值,并添加事件
復(fù)制代碼 代碼如下:
<html>
<head>
<title>測試JQUERY提交動態(tài)文本</title>
<script language="javascript" src="jquery.js"></script>
<script language="javascript">
$(function(){ //引用的jquery文件我就不上傳了,大家應(yīng)該都有的。
$("#a1").clone().appendTo("#ap");
var a=""; //定義全局變量 a;
txtadd();
alert(a); //測試全局變量是否有值;
$("#tall").blur(function(){ alert("測試一下"); }); //添加一個從同步事件里返回文本框的blur事件
$("#a1").blur(function(){ alert("本頁面事件!"); });//注意,clone出來的a1文本框不具有blur事件;
function txtadd(){
$.ajax({
async:false, //使用同步請求,因為異步請求不能將返回值傳給全局變量;
type:"post",
url:"autotxt.php",
data:{txtid1:1,txtid2:2},
beforeSend:function(){$("#tt").html("數(shù)據(jù)加載中。。。")},
success:function(data){$("#tt").html(decodeURI(data)); //autotxt.php返回值<input name='tall' id='tall' value='dc' maxlength='6'/>;
a=$("#tall").val(); //將返回值做處理給全局變量
}
});
}
})
</script>
</head>
<body>
<form action="autotxt.php" method="post">
<div id="tt"></div>
<div id="ap"></div>
<input type="text" id="a1" name="a1" value="測試" />
<input type="hidden" id="ok" name="ok" value="ok" />
<input type="submit" value="確定" />
</form>
</body>
</html>
您可能感興趣的文章:
- Jquery中$.ajax()方法參數(shù)詳解
- JQuery中$.ajax()方法參數(shù)詳解
- jQuery中$.ajax()和$.getJson()同步處理詳解
- jQuery中的$.ajax()方法應(yīng)用
- JQuery中$.ajax()方法參數(shù)詳解及應(yīng)用
- Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法總結(jié)
- jquery自定義類似$.ajax()的方法實現(xiàn)代碼
- JQuery的ajax的用法在asp中使用$.ajax()實現(xiàn)
- jquery $.ajax()取xml數(shù)據(jù)的小問題解決方法
- jQuery中$.ajax()方法參數(shù)解析
相關(guān)文章
淺談jQuery中hide和fadeOut的區(qū)別 show和fadeIn的區(qū)別
下面小編就為大家?guī)硪黄獪\談jQuery中hide和fadeOut的區(qū)別 show和fadeIn的區(qū)別。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08easyui messager alert 三秒后自動關(guān)閉提示的實例
下面小編就為大家?guī)硪黄猠asyui messager alert 三秒后自動關(guān)閉提示的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11jQuery實現(xiàn)鼠標(biāo)選中文字后彈出提示窗口效果【附demo源碼】
這篇文章主要介紹了jQuery實現(xiàn)鼠標(biāo)選中文字后彈出提示窗口效果,涉及jQuery事件響應(yīng)及頁面元素動態(tài)操作相關(guān)技巧,非常簡便實用,需要的朋友可以參考下2016-09-09