jQuery怎么加载一个html页面到我指定的div里面

jQuery怎么加载一个html页面到我指定的div里面,第1张

使用ajax。

参考代码:

$(function(){

$.ajax({

type:"POST",      url:"LoginLoadArticle.ashx",    

data: "type="+escape("最新公告") ,

success:function(msg){

$(".gonggao").html(msg)

      },      error:function(XMLHttpRequest, textStatus, thrownError){}

})

})

扩展资料:

xml:返回XML文档,可用JQuery处理。 

html:返回纯文本HTML信息;包含的script标签会在插入DOM时执行。 

script:返回纯文本JavaScript代码。不会自动缓存结果。除非设置了cache参数。注意在远程请求时(不在同一个域下),所有post请求都将转为get请求。 

json:返回JSON数据。 

jsonp:JSONP格式。使用SONP形式调用函数时,例如myurl?callback=?,JQuery将自动替换后一个“?”为正确的函数名,以执行回调函数。 

text:返回纯文本字符串。 

beforeSend:要求为Function类型的参数,发送请求前可以修改XMLHttpRequest对象的函数。

建议直接使用在线前端库,有免费的CDN加速,加载jQuery会更快

<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>

(function() {

var jsfiles = new Array(

"script/jquery.js",

"script/aaa.js"

)

var agent = navigator.userAgent

var docWrite = (agent.match("MSIE") || agent.match("Safari"))

if(docWrite) {

var allScriptTags = new Array(jsfiles.length)

}

var host = "lib/"   //文件的所在目录

for (var i=0, len=jsfiles.lengthi<leni++) {

if (docWrite) {

allScriptTags[i] = "<script src='" + host + jsfiles[i] +

"'><&#47script>"

} else {

var s = document.createElement("script")

s.src = host + jsfiles[i]

var h = document.getElementsByTagName("head").length ?

document.getElementsByTagName("head")[0] :

document.body

h.appendChild(s)

}

}

if (docWrite) {

document.write(allScriptTags.join(""))

}

})()

试试吧~这个是通过 js引用 JS的方法,需要引用的JS放到数组里就行了 jsfiles


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/11898084.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存