评论(0)
10年前说

最简添加删除class:

  1. // for test
  2. function $(id){ return document.getElementById(id); }
  3. // add or remove class
  4. $('test1').onclick = function(){
  5.     $('test2').className = /\s*on$/.test($('test2').className) ? 'test_class' : 'test_class on';
  6. };

最简显示隐藏:

  1. // for test
  2. function $(id){ return document.getElementById(id); }
  3. // display none or block
  4. $('test1').onclick = function(){
  5.     $('test2').style.display = $('test2').style.display == 'none' ? 'block' : 'none';
  6. };

最简Tab切换:

  1. <style>
  2.         ul li{cursor: pointer;}
  3.         div{display: none;}
  4.         .on{border: 1px solid #ddd;}
  5.         .on div{display: block;}
  6. </style>
  7. <ul id="x">
  8.     <li>Tab1<div>content1</div></li>
  9.     <li>Tab2<div>content2</div></li>
  10.     <li>Tab3<div>content3</div></li>
  11. </ul>
  12. <script type="text/javascript">
  13. document.getElementById('x').onclick = function(e){
  14.     var w=window.event,t=(e||w).target||w.srcElement,c='className',x=this.x;
  15.     x?x[c]='':0;tthis.x=t;t[c]='on';
  16. };
  17. </script>

Via 最小化DEMO测试代码

评论(0)
10年前说
  1. /**
  2.  * WordPress 媒体库只显示用户自己上传的文件
  3.  */
  4. //在文章编辑页面的[添加媒体]只显示用户自己上传的文件
  5. function my_upload_media( $wp_query_obj ) {
  6.     global $current_user$pagenow;
  7.     if( !is_a$current_user, 'WP_User') )
  8.         return;
  9.     if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
  10.         return;
  11.     if( !current_user_can( 'manage_options' ) && !current_user_can('manage_media_library') )
  12.         $wp_query_obj->set('author', $current_user->ID );
  13.     return;
  14. }
  15. add_action('pre_get_posts','my_upload_media');
  16. //在[媒体库]只显示用户上传的文件
  17. function my_media_library( $wp_query ) {
  18.     if ( strpos$_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
  19.         if ( !current_user_can( 'manage_options' ) && !current_user_can( 'manage_media_library' ) ) {
  20.             global $current_user;
  21.             $wp_query->set( 'author', $current_user->id );
  22.         }
  23.     }
  24. }
  25. add_filter('parse_query', 'my_media_library' );
评论(0)
10年前说
  1. <?php
  2.     $pc=$post->post_content;
  3.     $st=strip_tags(apply_filters('the_content',$pc));
  4.     if(has_excerpt())
  5.         the_excerpt();
  6.     elseif(preg_match('/<!--more.*?-->/',$pc) || mb_strwidth($st)<300)
  7.         the_content('Read more &raquo;');
  8.     elseif(function_exists('mb_strimwidth'))
  9.         echo wp_trim_words(strip_tags(apply_filters('the_content', $post->post_content)), $num_words = 100, $more = null);
  10.     else the_content();
  11. ?>
评论(0)
10年前说
  1. //2014-05-01 by huilang.me
    $('#header ul li a').bind('click', function(){
  2.     $('#content').stop().hide();
  3.     $('#loading').show();
  4.     $("#main").show(); //show #main
  5.     $('#main .close').show();
  6.     $('#main .close').click(function(){
  7.         $('#main').hide();
  8.     });
  9.         $('#header ul li a').removeClass('current');//remove current
  10.         $(this).addClass('current');//add current
  11.         $url = $(this).attr('href');//get current url
  12.         $.ajax({
  13.                 url: $url,
  14.                 cache: false,
  15.                 success: function(data){
  16.                     var content = $(data).find('#content').html();
  17.                     // alert(content);
  18.                     $('#loading').hide();
  19.                     $("#content").html(content).stop().fadeIn(400);//load content
  20.                     if( $("#content").find(".banner").length>0 ){
  21.                         slider = $('.banner ul').bxSlider({
  22.                             autoHover: true,
  23.                             auto: true,
  24.                         });
  25.                         // load current sliders
  26.                         function hl_count(){
  27.                             var $count = slider.getSlideCount();
  28.                             var $hl_count = ' / ' + $count;
  29.                             $(".bx-pager").append($hl_count);
  30.                         };
  31.                         hl_count()
  32.                     }
  33.                 }
  34.         });
  35.         return false;
  36. });
评论(0)
10年前说

禁止鼠标右键:oncontextmenu="return false";

禁止选择:onselectstart="return false";

禁止拖放:ondragstart="return false";

禁止拷贝:oncopy=document.selection.empty() 。

禁止保存:<noscript><iframe src="*.htm"></iframe></noscript>,放在head里面。

禁止粘贴:<input type=text onpaste="return false">

关闭输入法:<input>

屏蔽打印:

<style>

@media print{

* {display:none}

} </style>

DEMO

<html oncontextmenu="return false" oncopy='document.selection.empty()'>

评论(0)
10年前说
  1. if ( $('.testimonials ul').children().length > 1 ){
  2.     $('.testimonials ul').bxSlider({
  3.         auto: true,
  4.         mode: 'fade'
  5.     });
  6. }