Home  >  Article  >  Web Front-end  >  .html()为何只运行一次_html/css_WEB-ITnose

.html()为何只运行一次_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:37:141551browse

我想替换掉div里面的内容,但是运行完发现只替换的第一行,后面的都没替换,我现在想全部替换掉要如何写

<script type="text/javascript" src="jquery.js"></script><script type="text/javascript">        $(function () {            $('#div').html('xxxxx');        });</script>


<body>	<div id="div">内容</div>	<div id="div">内容</div>	<div id="div">内容</div>	<div id="div">内容</div></body>


回复讨论(解决方案)

$(function () {
            $('div').html('xxxxx');
        });
通过id获取只能得到一个

$(function () {
            $('div').html('xxxxx');
        });
通过id获取只能得到一个



那怎么能让它替换所有的id

<script> <br /> $(function () { <br /> $('[id=div]').html('xxxxx'); <br /> }); <br /> </script>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn