$(function(){
var $html = "<div id='test' title='hi'>我是调用函数创建的</div>";
$("body").append($html);
})
不需要默认的return,上面直接append($html)
var $html = "<div id='test' title='hi'>我是调用函数创建的</div>";
$("body").append($html);
})
不需要默认的return,上面直接append($html)
2015-06-05
不使用 if
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<a>简单</a>
</ul>
<script type="text/javascript">
$(function(){
var a = '更多';
$('a').click(function(){
var b = $(this).text();
$(this).text(a);
a = b;
$('li:lt(4)').toggle();
});
});
</script>
</body>
<body>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<a>简单</a>
</ul>
<script type="text/javascript">
$(function(){
var a = '更多';
$('a').click(function(){
var b = $(this).text();
$(this).text(a);
a = b;
$('li:lt(4)').toggle();
});
});
</script>
</body>
$("li:gt(3)").hide(); $("li:last").show();
$("a").click(function() {
if($("a").html() == "更多") {
$("li:gt(3)").show();
$("li:last").show();
$("a").html("简化"); }
else{$("li:gt(3)").hide();
$("li:last").show();
$("a").html("更多"); }})
$("a").click(function() {
if($("a").html() == "更多") {
$("li:gt(3)").show();
$("li:last").show();
$("a").html("简化"); }
else{$("li:gt(3)").hide();
$("li:last").show();
$("a").html("更多"); }})
<body>
<ul id="ul">
<li >1111111111</li>
<li>22222222222</li>
<li >3333333333</li>
<li>4444444444</li>
<li>55555555555</li>
<li>6666666</li>
<li>77777777777</li>
<li >88888888</li>
<a id="a" href="javascript:(0);">更多</a>
</ul>
</body>
<ul id="ul">
<li >1111111111</li>
<li>22222222222</li>
<li >3333333333</li>
<li>4444444444</li>
<li>55555555555</li>
<li>6666666</li>
<li>77777777777</li>
<li >88888888</li>
<a id="a" href="javascript:(0);">更多</a>
</ul>
</body>