網(wǎng)頁(yè)開(kāi)發(fā)中JavaScript傳遞參數(shù)方法比較
導(dǎo)語(yǔ):在開(kāi)發(fā)網(wǎng)頁(yè)時(shí),前臺(tái)后臺(tái)的數(shù)據(jù)交互是常有問(wèn)題,下面小編給大家提供了網(wǎng)頁(yè)開(kāi)發(fā)中JavaScript傳遞參數(shù)方法比較,大家可以參考閱讀,更多詳情請(qǐng)關(guān)注應(yīng)屆畢業(yè)生考試網(wǎng)。
1、通過(guò)window.location.href或者document.location.href進(jìn)行傳遞,比如window.location.href="/pic/p>
2、通過(guò)Ajax進(jìn)行數(shù)據(jù)的傳遞,格式如下:
$.ajax{
type: "post",
url: "test/index",
dataType: json,
data: $("#orderForm").serialize() ,
success: function(d){
alert(d.msg);
}
error:function(d){
alert(d.error);
}
}
其中data即代表著要傳遞的數(shù)據(jù)
3、通過(guò)Ajax的post方法進(jìn)行傳遞,格式如下:
$.post({
"url",
$("#orderForm").serialize(),
function(d){
alert(d.msg);
}
});
4、form表格中的action方法也可以傳遞數(shù)據(jù),但是action方法相對(duì)來(lái)說(shuō)傳遞的東西更為全面,可以跳到連接,也可以跳到文本、圖片、視頻等多媒體內(nèi)容,action里面的鏈接和window.location攜帶參數(shù)的方法是一樣的。
【網(wǎng)頁(yè)開(kāi)發(fā)中JavaScript傳遞參數(shù)方法比較】相關(guān)文章:
JavaScript如何獲取地址欄中傳遞參數(shù)09-14
java通過(guò)值傳遞參數(shù)的方法是什么03-12
C語(yǔ)言函數(shù)參數(shù)傳遞規(guī)律11-19
C語(yǔ)言函數(shù)調(diào)用與參數(shù)傳遞02-21