如何在我需要的脚本中使用substr函数 substr(0,25);
<a class="dep_buttons" href="#"> something text something text something text something text something text something text </a>
$('.dep_buttons').mouseover(function(){
if($(this).text().length > 30) {
$(this).stop().animate({height:"150px"},150);
}
$(".dep_buttons").mouseout(function(){
$(this).stop().animate({height:"40px"},150);
});
});
Run Code Online (Sandbox Code Playgroud)
Moo*_* GK 61
从字符串中提取字符:
var str = "Hello world!";
var res = str.substring(1,4);
Run Code Online (Sandbox Code Playgroud)
结果res
将是:
ell
Run Code Online (Sandbox Code Playgroud)
http://www.w3schools.com/jsref/jsref_substring.asp
$('.dep_buttons').mouseover(function(){
$(this).text().substring(0,25);
if($(this).text().length > 30) {
$(this).stop().animate({height:"150px"},150);
}
$(".dep_buttons").mouseout(function(){
$(this).stop().animate({height:"40px"},150);
});
});
Run Code Online (Sandbox Code Playgroud)
如果你想从a
标签中提取出来
$('.dep_buttons').text().substr(0,25)
Run Code Online (Sandbox Code Playgroud)
使用鼠标悬停事件,
$(this).text($(this).text().substr(0, 25));
Run Code Online (Sandbox Code Playgroud)
以上将提取标签的文本,然后再次提取将其分配回来.
归档时间: |
|
查看次数: |
149726 次 |
最近记录: |