Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
跨浏览器jquerydom操作_Jquery_Html_Debugging - Fatal编程技术网

跨浏览器jquerydom操作

跨浏览器jquerydom操作,jquery,html,debugging,Jquery,Html,Debugging,我正在使用这个jQuery代码段 $("a").html("<img> alt='example' src='example.jpg> </img>") $(“a”).html(“”) 在a标记内动态添加img标记。(注意,src='example,jpg没有结束单引号) 在Firefox中,img标签出现了,但在IE和opera中,img标签没有出现,所以我花了2个小时试图找出原因?最后才发现“单报价关闭问题” 有什么工具可以防止这种类型的错误吗?我认为您的代

我正在使用这个jQuery代码段

$("a").html("<img> alt='example' src='example.jpg> </img>")
$(“a”).html(“”)
a
标记内动态添加
img
标记。(注意,src='example,jpg没有结束单引号)

在Firefox中,
img
标签出现了,但在IE和opera中,
img
标签没有出现,所以我花了2个小时试图找出原因?最后才发现“单报价关闭问题”


有什么工具可以防止这种类型的错误吗?

我认为您的代码片段中有一些已经被吃掉了,否则它不会起任何作用。考虑到这是动态代码,唯一能够找到类似错误的工具是一些支持javascript的验证器

避免此错误的一种方法是使用jQuery设置src属性:

var img = $("<img>");
img.src = "example.jpg";
$("a").append(img);
var img=$(“
通过这种方式,您的文本编辑器可能会发现不匹配,如果没有,您将在评估JS时出错。

哇,我不知道$(“”)可以创建一个新的“img”标记。非常感谢