javascript - 如何更改 CSS 和 JS 中的 CSS 样式表?
问题描述
function colorChanger() {
var len = document.getElementById("string").value.length;
if (len < 50) {
style1.onclick = swapStyleSheet("first_50.css");
} else if (len > 50 && len < 100) {
style1.onclick = swapStyleSheet("second_100.css");
}
}
function swapStyleSheet(sheet){
document.getElementById('css_style').setAttribute('href', sheet);
}
less than 50
这是我的代码,如果字符数是并且我希望它更改样式表more than 50 and less than 100
我的代码不起作用
解决方案
这是我的代码,它正在更改样式表。
<html>
<head>
<title>
Change Css
</title>
<script lang="javascript">
function colorChanger() {
var len = document.getElementById("string").value.length;
if (len < 50) {
swapStyleSheet("first_50.css");
} else if (len > 50 && len < 100) {
swapStyleSheet("second_100.css");
}
}
function swapStyleSheet(strName) {
document.getElementById("cssChanger").href = strName;
}
</script>
<link href="first_50.css" id="cssChanger" />
</head>
<body>
<input type="text" id="string" value=""></input>
<input type="button" id='style1' value="Change Css" onclick="javascritpt:colorChanger();">
</body>
</html> ````
推荐阅读
- ios - iOS 13 上 PWA 和 WKWebView 的状态
- python - 如何使用 selenium 和 python 访问弹出模式 iframe 中的元素
- javascript - 在移动到其他字段集之前验证按钮单击的字段集
- jenkins - Nightwatch.js 无法在 Jenkins 管道上运行
- python - 使用 python 抓取嵌套表
- c - C管道写入/读取双打序列失败
- kotlin - 减号与减号的不同用例是什么?
- wordpress - Wordpress 多站点子域显示服务器空白页 [已解决]
- r - R中折线图和堆积条的不同比例如何区分
- python - 如何为matplotlib中的所有水平网格线添加垂直刻度线?