在IE8中,下面的代码报错:
- $('#invoiceListDot').text(htmlTemplate);
说明:invoiceListDot 是一个script标签
- <script id="invoiceListDot" type="text/x-dot-template">
- {{? it.invoiceInfoDtos}}
- {{ for(var prop=0;prop
- <it.invoiceInfoDtos.length
- ; prop++){ }}
- {{? it.invoiceInfoDtos[prop]}}
- <div class="{{ if(prop==0 && it.create==true){}}invoice-infor {{ }else {}}no-invoice{{ }}}"
- data-index="{{= prop }}">
- <span class="no-ivoice-icon"></span>
- <span>普通发票</span>
- <span class="ivo-margin invoiceType">{{= it.invoiceInfoDtos[prop].content }}</span>
- <span class="ivo-margin invoiceCompany">{{= it.invoiceInfoDtos[prop].title }}</span>
- <span class="ivo-margin invoiceAddress">{{= it.invoiceInfoDtos[prop].address }}</span>
- <span class="ivo-margin invoicePerson">{{= it.invoiceInfoDtos[prop].receiver }}</span>
- <span class="ivo-margin invoicePhone">{{= it.invoiceInfoDtos[prop].phone }}</span>
- </div>
- {{?}}
- {{ } }}
- {{?}}
- </script>
改为如下代码也报错:
- $('#invoiceListDot').html(htmlTemplate);
这是IE8的兼容性问题.
解决方法:
在js中判断浏览器类型,若是IE8,则执行
- $('#invoiceListDot').innerHTML = htmlTemplate;
整个逻辑判断如下:
- if (getBrowserVersion.isIE8) {
- $('#invoiceListDot').innerHTML = htmlTemplate;
- } else {
- $('#invoiceListDot').text(htmlTemplate);
- }
获取script标签的内容的时候:
- var tmplate = $invoiceListDot.text();//IE8中返回空字符串
- if (!tmplate) {
- console.log('$invoiceListDot.text() return null');
- tmplate = $invoiceListDot.html();
- }
new Date('2015-08-05 23:12:20')
在chrome中,下面的语法是正确的:
但是在IE8中不支持,所以增加了判断:
- if (typeof window.willEndTime == 'string') {//IE中
- productInfo2.willEndTime = window.willEndTime;
- } else {
- productInfo2.willEndTime = new Date(window.willEndTime).format("yyyy-MM-dd");
- }
那么如何判断浏览器是IE8呢?
- /***
- * get browser type and browser version and language
- when page open,the function will be executed automaticly
- * @param write22
- * @returns {{systemLanguage,userLanguage,ver}}
- */
- getBrowserVersion = (function (write22) {
- var browser = {};
- // console.dir(navigator);
- var userAgent = navigator.userAgent.toLowerCase();
- /*for(osvId in navigator){
- var value222=navigator[osvId];
- document.writeln(osvId+": "+value222+'<br>');
- }*/
- var lang22 = navigator.language;
- // document.writeln(userAgent+'<br>');
- // document.writeln(navigator.appCodeName+'<br>');
- var s;
- (s = userAgent.match(/msie ([\d.]+)/)) ? browser.ie = s[1] : (s = userAgent.match(/firefox\/([\d.]+)/)) ? browser.firefox = s[1] : (s = userAgent.match(/chrome\/([\d.]+)/)) ? browser.chrome = s[1] :
- (s = userAgent.match(/opera.([\d.]+)/)) ? browser.opera = s[1] : (s = userAgent.match(/version\/([\d.]+).*safari/)) ? browser.safari = s[1] : 0;
- var version = "";
- if (browser.ie) {
- version = browser.ie;
- if (write22 && write22 != false && write22 != 'false') {
- document.writeln('IE<br>');
- }
- if (!browser.lang || browser.lang == undefined) {
- lang22 = navigator.browserLanguage;
- browser.systemLanguage = navigator.systemLanguage;
- browser.userLanguage = navigator.userLanguage;
- }
- }
- else if (browser.firefox) {
- version = browser.firefox;
- browser.mozilla = browser.firefox;
- if (write22 && write22 != false && write22 != 'false') {
- document.writeln('firefox<br>');
- }
- }
- else if (browser.chrome) {
- version = browser.chrome;
- if (write22 && write22 != false && write22 != 'false') {
- document.writeln('chrome<br>');
- }
- }
- else if (browser.opera) {
- version = browser.opera;
- if (write22 && write22 != false && write22 != 'false') {
- document.writeln('opera<br>');
- }
- }
- else if (browser.safari) {
- version = browser.safari;
- if (write22 && write22 != false && write22 != 'false') {
- document.writeln('Safari<br>');
- }
- }
- else {
- version = 'unknown browser';
- }
- browser.ver = version;
- if (lang22 && lang22 != undefined) {
- browser.lang = lang22.toLowerCase();
- }
- browser.isIE8 = (browser.ie && (version === '8.0' || version === '8'));
- return browser;
- })();
上述脚本见附件
使用方法:
- f (getBrowserVersion.isIE8) {
- $('#invoiceListDot').innerHTML = htmlTemplate;
- } else {
- $('#invoiceListDot').text(htmlTemplate);
- }
Ie识别不了有空格的json
比如
{
"path":"huang wei"
}
IE7中动态创建表格时,必须要创建tbody,否则表格不显示
- var tb = put('table.service');
- if (BrowserVersion.isIE7 || BrowserVersion.isIE6) {
- tb=put(tb,'tbody');
- }