环境: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

GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐