在JQuery中设置$(this).text的样式
Styling $(this).text in JQuery
是在JQuery中设置文本样式的一种方式,例如:
例如。当我点击"显示表格"按钮时,它将由红色变为蓝色。
$(document).ready(function () {
$('#hide').on('click', function () {
if ($('#category-table').is(':visible')) {
$(this).text("Show Table"); /*style this text color: red;*/
$('#category-table').hide();
} else {
$(this).text("Hide Table"); /*style this text color: blue;*/
$('#category-table').show();
}
});
});
使用.css()
函数指定元素的样式:
$(this).text("Show Table").css('color', 'red');
或者你可以有CSS类,例如
.red {
color: red;
}
.blue {
color: blue;
}
并添加类:
$(this).text("Show Table").removeClass("blue").addClass("red");
使用jQuery.css()方法。
例如$(this).text("Show Table").css('color', 'red');
您似乎在使用jQuery。
$(this).css('color', '#ff0000'); /*style this text color: red;*/
$(this).text("Show Table");
$(this).css('color', '#0000ff'); /*style this text color: blue;*/
$(this).text("Hide Table");
$(document).ready(function () {
$('#hide').on('click', function () {
if ($('#category-table').is(':visible')) {
$(this).text("Show Table"); /*style this text color: red;*/
$(this).css("color","red"); // if you want set color (you can set color as 'red' or '#ff0000')
$(this).addClass("myRedClass"); //this is better, you can set class and change him in styles
$('#category-table').hide();
} else {
$(this).text("Hide Table"); /*style this text color: blue;*/
/* copy from red */
$('#category-table').show();
}
});
});
相关文章:
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 将样式表插入iframe
- 跟踪在页面加载时应用内联样式的JavaScript
- 如何将输入(type=text)从html表单传递到javascript函数
- 如果文本字段为空,则使用JavaScript应用CSS样式
- 定义完全独立的样式信息
- W3C循环样式的JavaScript
- jQuery/JavaScript在线公文包表单-打印样式表
- 使用递归、Ramda.js和无点样式重构字符串的getPermutations()
- FF和Chromium中CSS样式按钮的外观差异
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- 如何首先设置样式<td>表中包含在窗体中的元素
- javascript问题正文样式
- 使用具有内联样式的tidy-html5
- DataTables-创建自定义分页样式(加载更多样式)
- 具有所有样式的文本正在复制到可编辑文本区域
- 在文本区域中使用jQuery.text()保持换行符
- Javascript em根据窗口/视口尺寸调整大小,不影响文档样式的text/css
- 在JQuery中设置$(this).text的样式
- Flask:资源被解释为样式表,但使用MIME类型text/html传输