<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><style>div { width:100px; height:120px; background:red; }</style><!--<script src="miaov.js"></script>--><script>function $( v ){ if( typeof v === 'function' ){ return window.onload = v; //console.log(v) } else if ( typeof v === 'string' ) { return document.getElementById(v); } else if ( typeof v === 'object' ) { return v; }}$(function(){ // $('div1').style.width = '300px'; $('btn1').onclick = function (){ //var aaa=getComputedStyle( $('div1')).width || $('div1').currentStyle.width var aaa= $('div1').currentStyle.width || getComputedStyle( $('div1')).width ***//在這里用申明變量的方式寫了ie和chrome的獲取元素樣式的寫法,為什么會報錯的?備注:這里用的$不是jquery,而是上面定義的$函數*** alert(aaa) };});</script></head><body><input id="btn1" type="button" value="按鈕" /><div id="div1"></div></body></html>
關于獲取元素樣式的兼容性寫法為什么不行呢?
翻閱古今
2018-12-20 18:15:42