使用jquery html()方法设置div的html问题 [英] Issue while setting html of div using the jquery html() method
本文介绍了使用jquery html()方法设置div的html问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了jquery问题,我使用html方法设置了div的html,但它没有正确设置。
这里是剥离我使用的下拉代码:
<?xml version ='1.0'encoding ='utf-8'?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html>
< head>
< script language =javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.jstype =text / javascript> < /脚本>
< script type ='text / javascript'>
jQuery(document).ready(function($){
$('#results')。html(< div class ='tweet'>< a href = javascript:sendDirectMessage '1711838','abc')> DM< / a>< hr />< / div>);
})
< / script>
< / head>
< body>
< div id =results/>
< / body>
< / html>
但是当我使用萤火虫在生成的页面中查看结果时,元素的内容设置为:
< a)=abc =href =javascript:sendDirectMessage('1711838',> DM< ; / a>
我做错了什么?
< a href = \javascript:sendDirectMessage('1711838','abc')\>
I've got an issue with jquery where I set the html of a div using the html method, but it does not set it correctly.
Here's the stripped down code I'm using:
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js" type="text/javascript"></script>
<script type='text/javascript'>
jQuery(document).ready(function($) {
$('#results').html("<div class='tweet'><a href=javascript:sendDirectMessage('1711838', 'abc')>DM</a><hr/></div>");
})
</script>
</head>
<body>
<div id="results"/>
</body>
</html>
but when I view the result in the generated page using firebug, the element has it's contents set to:
<a )="" abc="" href="javascript:sendDirectMessage('1711838',">DM</a>
What am I doing wrong??
解决方案
Perhaps you should enclose with double quotes:
<a href=\"javascript:sendDirectMessage('1711838', 'abc')\">
这篇关于使用jquery html()方法设置div的html问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文