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

WBOY
Release: 2016-06-24 11:37:14
Original
1559 people have browsed it

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

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


<body>	<div id="div">内容</div>	<div id="div">内容</div>	<div id="div">内容</div>	<div id="div">内容</div></body>
Copy after login


回复讨论(解决方案)

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

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



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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!