前端如何解決瀏覽器兼容性問題,jQuery 項目 兼容IE ,緩存問題,等總結

 2023-10-01 阅读 33 评论 0

摘要:不支持ES6語法 option += '<p class="actionsw" value="'+data[i].type+'" text = "'+data[i].sourceId+'" style="font-size: 16px"><span>'+title+&

不支持ES6語法

 option +=  '<p  class="actionsw" value="'+data[i].type+'"  text = "'+data[i].sourceId+'" style="font-size: 16px"><span>'+title+'</span></p>';

不支持onclick事件

   $(".actionsw").click(function () {var type= $(this).attr("value")var sourceId= $(this).attr("text");})

ajax,樹控件,緩存問題

url+"?"+“t=”+Math.random()
		$(function() {var url = $.common.isEmpty(excludeId) ? prefix + "/treeData": prefix + "/treeData/" + excludeId;var options = {url: url+"?"+"t="+Math.random(),expandLevel: 2,onClick : zOnClick};$.tree.init(options);});

js加時間戳

<script th:src="@{/js/index.js?t=' + new Date().getTime()+'}" type="text/javascript"></script>

獲取鍵盤事件的鍵盤碼的兼容問題

document.onkeydown=function(ev){var e=ev||window.event;var keyCode=e.keyCode||e.which;console.log(keyCode);
}

阻止事件的默認行為的兼容問題

<a href="javascript:void(0)" >點擊跳轉到百度</a>
<form action="javascript:void(0)" ><input type="text"><button id="link">表單里面的button</button>
</form> 
document.oncontextmenu = function( ev ){var e = ev || window.event;if(e.preventDefault){e.preventDefault();}else{e.returnValue = false;//return false也可以阻止默認事件但是適合后面沒有其他邏輯代碼,否則會終止函數執行}
} 

阻止事件冒泡的兼容問題

document.onclick = function( ev ){var e = ev || window.event;if(e.stopPropagation){e.stopPropagation();}else{e.cancelBubble = true;}
} 

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/109169.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息