在下面的代码中,我已经说明了我想要实现的目标……通过向现有的 CSS 类添加新规则来改变它。
<head>
<style>
h4.icontitle
{font-size: 22pt;}
</style>
</head>
<body>
<script type="text/javascript">
textpercent = 84;
document.styleSheets[1].cssRules.['h4.icontitle'].style.setProperty('-webkit-text-size-adjust', textpercent+'%', null);
</script>
<h4> hello </h4>
</body>
Run Code Online (Sandbox Code Playgroud)
这是针对在不同尺寸的屏幕上运行的站点的预处理元素。结果将是...
h4.icontitle
{font-size: 22pt;
-webkit-text-size-adjust:84%;}
Run Code Online (Sandbox Code Playgroud)
在检查 DOM 时将可见。
任何想法都会受到欢迎。仅 Javascript - 这里没有 JQuery ......
解决了。
经过大量的反复试验,这里有一个工作功能,它允许 javascript 将样式直接插入到 CSS 中
function changeCSS(typeAndClass, newRule, newValue)
{
var thisCSS=document.styleSheets[0]
var ruleSearch=thisCSS.cssRules? thisCSS.cssRules: thisCSS.rules
for (i=0; i<ruleSearch.length; i++)
{
if(ruleSearch[i].selectorText==typeAndClass)
{
var target=ruleSearch[i]
break;
}
}
target.style[newRule] = newValue;
}
Run Code Online (Sandbox Code Playgroud)
与
changeCSS("h4.icontitle","backgroundColor", "green");
Run Code Online (Sandbox Code Playgroud)
希望其他人会发现这是在纯 javascript 中在其 CSS 中使用变量的有用方法。
我正在运行DHTML页面并希望缓存引用的HTML,PHP文件和IMAGE文件.
我在WWW.sitename.COM/sub-dir/中有以下所有文件
的.htaccess
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType text/cache-manifest .manifest
AddHandler server-parsed .html
AddHandler application/x-httpd-php .html .htm
Run Code Online (Sandbox Code Playgroud)
cache.manifest
CACHE MANIFEST
# Cache manifest version 0.0.00002
NETWORK:
CACHE:
http://WWW.sitename.COM/sub-dir/index.html
http://WWW.sitename.COM/sub-dir/this.php
http://WWW.sitename.COM/sub-dir/images/first.png
http://WWW.sitename.COM/sub-dir/images/second.png
FALLBACK:
Run Code Online (Sandbox Code Playgroud)
THIS.PHP文件中的HTML清单引用...
<html manifest="http://WWW.sitename.COM/sub-dir/cache.manifest">
Run Code Online (Sandbox Code Playgroud)
用于检测缓存活动的脚本
<script type="text/javascript">
var cacheStatusValues = [];
cacheStatusValues[0] = 'uncached';
cacheStatusValues[1] = 'idle';
cacheStatusValues[2] = 'checking';
cacheStatusValues[3] = 'downloading';
cacheStatusValues[4] = 'updateready';
cacheStatusValues[5] = 'obsolete';
var cache = window.applicationCache;
cache.addEventListener('cached', logEvent, false);
cache.addEventListener('checking', logEvent, false);
cache.addEventListener('downloading', logEvent, false);
cache.addEventListener('error', logEvent, false);
cache.addEventListener('noupdate', logEvent, …Run Code Online (Sandbox Code Playgroud) .htaccess ×1
caching ×1
class ×1
css ×1
dynamic ×1
html ×1
ipad ×1
javascript ×1
manifest ×1
stylesheet ×1