bootstrap处理缓存问题的方法:1、在关闭的时候清除数据;2、修改请求的URL,并在请求的URL上加上时间戳,语句如“function remoteUrl(u){...}”。

本教程操作环境:Windows7系统、bootsrap3.3.7版,Dell G3电脑。
百度了一下,有很多类似的情况,解决办法基本都是如下两种:
1、在关闭的时候清除数据:
1 2 3 | $( "#myModal" ).on( "hidden.bs.modal" , function () {
$(this).removeData( "bs.modal" );
});
|
Salin selepas log masuk
2、修改请求的URL,在请求的URL上加上时间戳。
1 2 3 4 5 6 7 | function remoteUrl(u){
u += '&t=' + Math.random(1000)
$.get(u, '', function (data){
$('#remoteModal .modal-body').html(data)
})
$('#remoteModal').modal({show:true,backdrop:false})
}
|
Salin selepas log masuk
上边的两个解决办法确实有效,但在IE中,第1种方法无效,第2种方法解决起来太繁琐。
我又百度到了另一种解决办法,专门针对IE的:
1 | [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*" )]
|
Salin selepas log masuk
该办法是要在服务器端给每个action加上,这样的话,这需要加多少action,那位作者居然嫌弃IE太垃圾了应该退出互联网界。
好了,吐糟完了,来上我的解决办法:直接修改bootstrap.js文件
位置在大约在1068行的位置,如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | $(document).on('click.bs.modal.data-api', '[data-toggle= "modal" ]', function (e) {
var $this = $(this)
var href = $this .attr('href')
var $target = $( $this .attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, '')))
var remoteUrl = !/#/.test(href) && href
if (remoteUrl == undefined) {
remoteUrl = "" ;
}
if (remoteUrl.indexOf( "?" ) > -1) {
remoteUrl += "&" + ( new Date ()).valueOf()
}
else {
remoteUrl += "?" + ( new Date ()).valueOf()
}
var option = $target .data('modal') ? 'toggle' : $.extend({ remote: remoteUrl }, $target .data(), $this .data())
e.preventDefault()
$target
.modal(option, this)
.one('hide', function () {
$this .is(':visible') && $this .focus()
})
})
|
Salin selepas log masuk
注释已经说明了解决办法,我只是增加了remoteUrl,在请求的url后加上时间,这样就不用一个一个的修改,也能兼顾各个浏览器了。
推荐:《bootstrap视频教程》《css视频教程》
Atas ialah kandungan terperinci bootstrap怎么处理缓存问题. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!