<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>test</title>
<script type="text/javascript">
function load(){
//document.getElementById("css").value;
//如何执行文本框这里的CSS代码?
}
</script>
</head>
<body>
<textarea id="css">
.aaa{width:200px;height:120px;background:red;}
.bbb{width:200px;height:40px;background:blue;}
</textarea><div class="aaa"></div>
<div class="bbb"></div><input type="button" value="load..." onclick="load();" />
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>test</title>
<script type="text/javascript">
function load(){
//document.getElementById("css").value;
//如何执行文本框这里的CSS代码?
}
</script>
</head>
<body>
<textarea id="css">
.aaa{width:200px;height:120px;background:red;}
.bbb{width:200px;height:40px;background:blue;}
</textarea><div class="aaa"></div>
<div class="bbb"></div><input type="button" value="load..." onclick="load();" />
</body>
</html>
解决方案 »
- 清熟悉jQuery的朋友給推荐个图片预览的插件
- 怎麼释放jquery ajax消耗的内存?
- CheckBox被点击后,文本框背景色为什么不能为灰色!!!
- ifrmae
- 不想白白浪费时间~有没有救我一下啊~郁闷ing..........~没分难道真的没人来帮一下吗?真够贱的
- 点击+按妞就+一行html里的元素,点-按妞就减少一行,如何实现,请大家帮忙!
- 一个css的问题
- 这种效果的界面如何作出来,在线等!
- 高手快来拿分 !!!!!!!!!!!!!
- 如何在某一页面关闭的时候执行某个自定义函数,刷新时不执行,如果使用unload事件,刷新页面也会执行。
- 在IE6中没错, 在IE 7 中 提示 类不能支持 Automation 操作
- 可以在地址栏里 ,调用页面中的JavaScript函数吗
你的css样式的位置也放得不对<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<style text="text/css">
.aaa{width:200px;height:120px;background:red;}
.bbb{width:200px;height:40px;background:blue;}
</style>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>test</title>
<script type="text/javascript">
function load(){
//document.getElementById("css").value;
//如何执行文本框这里的CSS代码?
}
</script>
</head>
<body>
<textarea id="css">
</textarea>
<div class="aaa">
</div>
<div class="bbb">
</div>
<input type="button" value="load..." onclick="load();"/>
</body>
</html>
document.getElementById("").style.height
document.getElementById("").style.background你的那段CSS代码是一串字符串,你真要执行,那么解析字符串,然后调用函数把对应属性加到对应的html标签上。
.aaa{width:200px;height:120px;background:red;}
.bbb{width:200px;height:40px;background:blue;}
</textarea><div class="aaa"></div>
<div class="bbb"></div>
这里的内容随时会变的,并不是一直这样的通过JS执行textarea里的CSS代码,使
<div class="aaa"></div>
<div class="bbb"></div>
达到指定的效果
<script language="javascript" type="text/javascript">
function changeCSS(n){
var cssvl=document.getElementById('css');
cssvl.href=n+".css";
}
changeCss('1')
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>test</title>
<script type= "text/javascript" src= "jquery-1.2.6.js"> </script>
<script type="text/javascript">
$(function(){
$("#load").click(function(){
var cssvalue=$("#css").val();
var newvalue="<style type='text/css'>"+cssvalue+"</style>"
$("head").append(newvalue);
});
})
</script>
</head>
<body>
<textarea id="css">
.aaa{width:200px;height:120px;background:red;}
.bbb{width:200px;height:40px;background:blue;}
</textarea> <div class="aaa"></div>
<div class="bbb"></div> <input id="load" type="button" value="loadJQUERY" />
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>test</title>
<script type="text/javascript">
var loadCSS=function(){
var css=document.createElement("style");
css.setAttribute("type","text/css");
if(css.styleSheet){ //For IE
css.styleSheet.cssText = document.getElementById('css').innerHTML;
}else {
var css_text = document.createTextNode(document.getElementById('css').innerHTML);
css.appendChild(css_text);} document.getElementsByTagName('head')[0].appendChild(css);
};
</script>
</head>
<body>
<textarea id="css">
.aaa{width:200px;height:120px;background:red;}
.bbb{width:200px;height:40px;background:blue;}
</textarea> <div class="aaa"></div>
<div class="bbb"></div> <input type="button" value="loadCSS" onclick="loadCSS()"/>
</body>
</html>