jquery之div的text() 方法,无参返回值,有参设置值
2013-12-10 11:00
375 查看
1
HTML Code
<divid="clickMe">
Click here and watch the text change!
</div>
CSS Code
div#clickMe {
width: 300px;
height: 100px;
margin: 10px;
background-color:
green;
color: white;
border: 1px solid black;
}
JavaScript Code
$(document).ready(function(){
//e is the event variable, can prevent the default behavior
//of the event or stop it from propogating up to the element's
//parent elements
$('div#clickMe').click(function(e){
var oldText
= $(this).text();
$(this).text(oldText
+'Click added some text!');
});
});
效果:
HTML Code
<divid="clickMe">
Click here and watch the text change!
</div>
CSS Code
div#clickMe {
width: 300px;
height: 100px;
margin: 10px;
background-color:
green;
color: white;
border: 1px solid black;
}
JavaScript Code
$(document).ready(function(){
//e is the event variable, can prevent the default behavior
//of the event or stop it from propogating up to the element's
//parent elements
$('div#clickMe').click(function(e){
var oldText
= $(this).text();
$(this).text(oldText
+'Click added some text!');
});
});
效果:
相关文章推荐
- JQuery设置DIV的text("")造成IE崩溃解决方法
- jquery中html()或text()方法获取或设置p标签的值
- jQuery设置div一直在页面顶部显示的方法
- jquery设置text的值示例(设置文本框 DIV 表单值)
- jquery设置text的值示例(设置文本框 DIV 表单值)
- jQuery 获取、设置HTML或TEXT内容的两种方法
- jquery中html()或text()方法获取或设置p标签的值
- Jquery的text()和html()方法在li与div取值结果解析
- jQuery 获取、设置HTML或TEXT内容的两种方法
- jquery之设置元素内容(替换HTML或文本内容,使用html()和text()方法)
- jQuery 获取、设置HTML或TEXT内容的两种方法
- text、html、val、attr(Jquery设置方法)
- jQuery设置div一直在页面顶部显示的方法
- Jquery的text()和html()方法在li与div取值结果解析
- jquery设置text的值示例(设置文本框 DIV 表单值)
- jquery中ajax方法返回的三种数据类型:text、json、xml;
- jquery 中的html()方法与text()的区别
- Jquery设置select控件指定text的值为选中项
- jquery的 ajax返回值为中文时乱码解决方法
- table和div设置height:100%无效的完美解决方法