分类目录归档:Javascript学习笔记

js,jquery,toggle方法的点击切换

                <ul class="zj_tab2">
                    {foreach $category_list as $k=>$v}

                    <li {if $v['id']==48}id="sun_cate1" class="active" style=""{/if}>
<!--                    <a href="/index/index/{$v['actions']}/type/{$v['id']}">{$v['name']}</a>-->
<!--                    <a href="javascript:void(0)">{$v['name']}</a>-->
                    {$v['name']}{if $v['id']==48}&nbsp;>{/if}
                    {if $v['id']==48}
                        {if !empty($sun_category)}
                            <ul id="sun_cate" class="hid zj_tab2">
                                {volist name="sun_category" id="sun"}
                                <li>{$sun.name}</li>
                                {/volist}
                            </ul>
                        {/if}
                    {/if}
                    </li>
                    {/foreach}
                    <script>
                            $("#sun_cate1").on("click", function()
                            {
                                $("#sun_cate").toggle(
                                    function(){
                                        console.log('bbbbb');
                                        $(this).addClass("hid");
                                    },
                                    function(){
                                        console.log('aaaaa');
                                        $(this).removeClass("hid");
                                    }
                                )
                            })
                    </script>

代码片断:js:tab切换

<code></code>
<div class=”gzzxq_toub-two-row”>
<div class=”item active”>专利</div>
<div class=”item”>论文</div>
<div class=”item”>成果</div>
<div class=”item”>新品种</div>
<div class=”item”>新技术引进</div>
<div class=”item”>新材料</div>
<div class=”item”>其他</div>
</div>
<div class=”main “>{volist name=”research_list” id=”item”}
{if empty($item)}
<div class=”mains{$key+1}” style=”display: none;”><a href=”#”>暂无科研产出</a></div>
{else}
<div class=”mains{$key+1}”>
<div class=”gzzxq-main-nr”>
<ul class=”gzzxq-main-nr_list”>
<li style=”list-style-type: none;”>
<ul class=”gzzxq-main-nr_list”>{volist name=”item” id=”iitem”}
<li><a href=”#”>{$iitem.biaoti}</a></li>
</ul>
</li>
</ul>
{/volist}

</div>
</div>
{/if}
{/volist}

<code>

 

<script>
window.onload=chengjiu();
function chengjiu(){
console.log($(“.main>div:first-child”));
$(“.main>div:first-child”)[0].style.cssText = “display:block;”;
$(‘.gzzxq_toub-two-row .item’).click(function () {
$(‘.gzzxq_toub-two-row .item’).removeClass(‘active’)
$(this).addClass(‘active’)
// if($(this))
// if($(“.main div”)){
// console.log($(“.main>div”)[0].style.cssText = “display:none”);
// };
$(“.main>div”).hide()
$(“.main>div”).eq($(this).index()).show()
// console.log($(“.main>div”).eq($(this).index()))
})
$(“.center-top-rows-span1″).each(function () {
var str = $(this).html();
var subStr = str.substring(0, 16);
$(this).html(subStr + (str.length > 16 ? ‘…’ : ”));
});
}
</script>

js效果,文字向上滚动

<div class="contents " style="overflow: hidden;">
    <div class="scroll-box">
     <ul class="list clar">
         {volist name="articleinfo" id="item"}
            <li>
                   <div class="art">
                       <img src="{$item.thumb.0.file}" alt="" width="210px" height="150px">
                       <div class="art-content">
                           <h1 class="title" style="line-height:20px;margin:0px;padding:0px;margin-bottom:23px;margin-top:5px;">{$item.title}</h1>
                           <p style="margin:0px;padding:0px;line-height:10px;">来源:{$item.source}</p>
                           <p style="margin:0px;padding:0px;line-height:10px;padding-left:20px;font-weight:none">日期:{:date('Y-m-d',$item.sdate)}</p>
                           <p class="text" style="width:95%;margin-top:20px;line-height:30px;color:#444">{$item.desc}</p>
                       </div>
                   </div>
            </li>
        {/volist}
     </ul>
    </div>

继续阅读

js的foreach方法,数组处理

<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p>点击按钮列出数组的每个元素。</p>
<button onclick=”numbers.forEach(myFunction)”>点我</button>
<p id=”demo”></p>

<script>
demoP = document.getElementById(“demo”);
var numbers = [4, 9, 16, 25];

function myFunction(item, index) {
demoP.innerHTML = demoP.innerHTML + “index[” + index + “]: ” + item + “<br>”;
}
</script>