jQuery.html()返回无效的IMG [英] jQuery.html() returns invalid IMG
问题描述
可能重复:
Jquery html()和自闭标签
是否期望jQuery $('span')。html()将XHTML br标签转换为html语法?
我有这样的文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="/js/core/jquery.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<img src="/some/image.gif" />
</div>
</body>
</html>
我想为某些节点检索html以执行某些操作。但我发现IMG存在一个问题。
I want to retrive html for some nodes to do something. But I see one problem with IMG.
$('#content').html();
这将返回无效的XHTML
This returns invalid XHTML
<img src="/some/image.gif">
jQuery版本是1.4.2。
jQuery version is 1.4.2.
推荐答案
这是重复的,但原始问题中的答案都没有给出实际的解决方法。 (可能是正确的。我不得不同意@Cletus在他的内容中所说的 - 一如既往的优秀答案。)
This is a duplicate, but none of the answers in the original question gives an actual workaround. (Probably rightly so. I can't but agree with what @Cletus says in his - as always excellent - answer.)
但如果你坚持使用XHTML:有一个 jQuery插件提供 innerXHTML()
功能(很差)尽管如此,最近更新了2007年,并且从未通过Beta)和一个名为 innerXHTML 的JavaScript工具承诺做你需要的。如果你需要这个,这可能是你最好的选择。
But if you're stuck with XHTML: there is a jQuery plugin providing a innerXHTML()
function (poorly maintained though, last updated 2007, and never made it from Beta) and a JavaScript tool named innerXHTML that promises to do what you need. If you need this, that may be your best bet.
这篇关于jQuery.html()返回无效的IMG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!