Uncaught SyntaxError: Failed to set the 'innerHTML' property on 'Element'

环境:win7 64位,apache,chrome 44.0.2403.125

写了下面一个xhtml文件

<?xml version="1.0" encoding="UTF-8"?>
<html xml:lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:epub="http://www.idpf.org/2007/ops">
	<head>
		<meta charset="UTF-8"/>
		<meta name="viewport" content="width=768, height=1024"/>
		<script type="text/javascript" src="scripts/jquery.js"/>
		<script type="text/javascript" src="scripts/jquery.mobile.min.js"/>
		<link rel="stylesheet" type="text/css" href="./scripts/jquery.mobile.min.css"/>
	</head>
	<body data-width="768" data-height="1024">
		<a style="z-index:1;" href="chapter-001.xhtml">abcd</a>
	</body>
</html>

点击链接时报错:

Uncaught SyntaxError: Failed to set the 'innerHTML' property on 'Element': The provided markup is invalid XML, and therefore cannot be inserted into an XML document.

出错行是jquery.mobile-1.4.2.js的4911行

//workaround to allow scripts to execute when included in page divs
all.get( 0 ).innerHTML = html;

原因:

XHTML does not support document.write or .innerHTML. Due to the fact, that jQuery inserts the new code using one of these methods, all XHTML compatible browsers will error out.

XHTML with application/xhtml+xml does not support raw modification of the source using any of these jQuery methods: .append(), .html(), .insert...(), etc.

Instead, query for some JSON data and insert the AJAX-received values into either pre-defined tags using .text() / .val() or dynamically create those nodes using document.createElement('someTag').

https://www.w3.org/MarkUp/2004/xhtml-faq#docwrite

解决:

在a标签里添加

data-ajax="false"

即:

<a style="z-index:1;" href="chapter-001.xhtml" data-ajax="false">abcd</a>

参考:

http://stackoverflow.com/questions/27824609/uncaught-syntaxerror-failed-to-set-the-innerhtml-property-on-element-the-p

http://blog.csdn.net/coolcoffee168/article/details/24966689

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值