$ ( function ( ) {
var lileng = gyslist. length;
var gyswidth = $ ( "#supplier" ) . width ( ) ;
var gyslist = $ ( "#supplier li" )
var sumWidth = 0 ;
for ( i = 0 ; i < gyslist. length; i++ ) {
if ( i === ( gyslist. length - 1 ) ) {
sumWidth += gyslist. eq ( i) . outerWidth ( ) ;
} else {
sumWidth += gyslist. eq ( i) . outerWidth ( ) + 30 ;
}
}
console. log ( sumWidth )
if ( sumWidth > gyswidth ) {
$ ( ".dxCon .sl-ext-gd" ) . show ( ) ;
} else {
$ ( ".dxCon .sl-ext-gd" ) . hide ( ) ;
}
} )
给每一个li后面添加顿号、最后一个li不加顿号 多选勾选不能超过3个,超出禁止勾选弹出提示
$ ( '.company li' ) . click ( function ( ) {
$ ( this ) . toggleClass ( 'current' ) ;
var num = $ ( this ) . parent ( ) . children ( 'li.current' ) . length;
if ( num > 3 ) {
$ ( this ) . toggleClass ( 'current' ) ;
alert ( "超出限制" )
}
} )
$ ( '.left_menu' ) . hover ( function ( ) {
$ ( this ) . stop ( ) . animate ( { width : '345' } , "slow" ) ;
} , function ( ) {
$ ( this ) . stop ( ) . animate ( { width : '225' } , "slow" ) ;
} )
< p style = " width : 200px; " class = " description" > 测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试</ p>
< style>
p { word-break : break-all; }
</ style>
String. getBlength = function ( str ) {
for ( var i = str. length, n = 0 ; i-- ; ) {
n += str. charCodeAt ( i) > 255 ? 2 : 1 ;
}
return n;
}
String. cutByte = function ( str, len, endstr ) {
var len = + len,
endstr = typeof ( endstr) == 'undefined' ? "..." : endstr. toString ( ) ,
endstrBl = this . getBlength ( endstr) ;
function n2 ( a ) { var n = a / 2 | 0 ; return ( n > 0 ? n : 1 ) }
if ( ! ( str + "" ) . length || ! len || len <= 0 ) {
return "" ;
}
if ( len< endstrBl) {
endstr = "" ;
endstrBl = 0 ;
}
var lenS = len - endstrBl,
_lenS = 0 ,
_strl = 0 ;
while ( _strl <= lenS) {
var _lenS1 = n2 ( lenS - _strl) ,
addn = this . getBlength ( str. substr ( _lenS, _lenS1) ) ;
if ( addn == 0 ) { return str; }
_strl += addn
_lenS += _lenS1
}
if ( str. length - _lenS > endstrBl || this . getBlength ( str. substring ( _lenS- 1 ) ) > endstrBl) {
return str. substr ( 0 , _lenS - 1 ) + endstr
} else {
return str;
}
}
function wordlimit ( cname, wordlength ) {
var cname = document. getElementsByClassName ( cname) ;
for ( var i = 0 ; i < cname. length; i++ ) {
var text = cname[ i] . innerHTML;
if ( String. getBlength ( text) <= wordlength) {
cname[ i] . innerHTML = text;
} else {
var result = String. cutByte ( text, wordlength, '' ) ;
cname[ i] . innerHTML = result + '...' ;
}
}
}
wordlimit ( 'description' , 20 )
点击按钮展开内容,再次点击按钮收起内容(按钮样式也同时改变)
< div class = " all" >
< div class = " title" > < span class = " open-icon" > </ span> </ div>
< div class = " con" > 我是内容</ div>
</ div>
< style>
* { margin : 0; padding : 0; }
.all { margin : 20px; }
.all .open-icon { background : url ( open.png) no-repeat center; width : 19px; height : 20px; -webkit-transition : -webkit-transform .5s linear; transition : -webkit-transform .5s linear; transition : transform .5s linear; transition : transform .5s linear, -webkit-transform .5s linear; -webkit-transform : rotate ( 0deg) ; transform : rotate ( 0deg) ; cursor : pointer; display : inline-block; vertical-align : middle; margin-top : -3px; margin-left : 4px; }
.all .put-icon { -webkit-transform : rotate ( -180deg) ; transform : rotate ( -180deg) ; }
</ style>
< script type = " text/javascript" src = " jquery.min.js" > </ script>
< script>
$ ( function ( ) {
$ ( '.title span' ) . click ( function ( ) {
if ( $ ( '.title span' ) . hasClass ( 'put-icon' ) ) {
$ ( this ) . removeClass ( 'put-icon' ) ;
} else {
$ ( this ) . addClass ( 'put-icon' ) ;
}
$ ( this ) . parents ( '.all' ) . find ( '.con' ) . slideToggle ( ) ;
} ) ;
} ) ;
</ script>
$ ( document) . ready ( function ( ) {
$ ( "div a" ) . attr ( "target" , "_blank" ) ;
} )
$ ( function ( ) {
$ ( '.btn' ) . click ( function ( event ) {
clearTimeout ( timer) ;
$ ( '.touming,.Content' ) . show ( ) ;
} ) ;
$ ( '.close' ) . click ( function ( event ) {
$ ( '.touming,.Content' ) . hide ( ) ;
} ) ;
var timer;
timer = setTimeout ( function ( ) {
$ ( '.touming,.Content' ) . show ( ) ;
} , 5000 )
} ) ;