03
2018
08

jquery元素内和元素前后添加文字

<button id="hxjxjs" type="button">元素内文字后加内容</button>

<button id="hxjn" type="button">元素内文字前加内容</button>

<button id="xjswzr" type="button">元素外元素后面加内容</button>

<button id="xjgnxg" type="button">元素外元素前面加内容</button>

<div class="anco">

中国电信:

</div>


<script type="text/javascript">

$(document).ready(function(){//页面加载完在执行jq

$('#hxjxjs').click(function(){

$('.anco').append('号段是133,189')//支持加入div或是html代码

});

$('#hxjn').click(function(){

$('.anco').prepend('中国联通比电信好')

});

$('#xjswzr').click(function(){

$('.anco').after('你看看是不是在div外面加的,外面的后面')

})

$('#xjgnxg').click(function(){

$('.anco').before('这是在div前面加了字')

})


});

</script>


« 上一篇下一篇 »