
直接去掉font标签
正则表达式:/<font<\/font>/g
只是去掉时间
正则表达式:/(<font>)(<\/font>)/g 替换内容:$1$2
使用示例如下:
var str = "2016-05-28 16:17:00<font color='#FF0000'>4794</font>";// 第一种,输出结果:2016-05-28 16:17:00
consolelog(strreplace(/<font<\/font>/g,""));
// 第二种,输出结果:2016-05-28 16:17:00<font color='#FF0000'></font>
consolelog(strreplace(/(<font>)(<\/font>)/g ,"$1$2"));
按需选择吧
自己试试吧:
<!doctype html public "-//w3c//dtd html 40 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="属性,样式,元素,写法,页面">
<meta name="description" content="直接去掉font标签正则表达式:/<font<\/font>/g只是去掉时间正则表达式:/(<font>)(<\/font>)/g 替换内容: property="position" content="1" />
JS 正则 替换font里的内容 2016-05-28 16:17:00<font color="#FF0000">4794<font> 次

直接去掉font标签
正则表达式:/<font<\/font>/g
只是去掉时间
正则表达式:/(<font>)(<\/font>)/g 替换内容:$1$2
使用示例如下:
var str = "2016-05-28 16:17:00<font color='#FF0000'>4794</font>";// 第一种,输出结果:2016-05-28 16:17:00
consolelog(strreplace(/<font<\/font>/g,""));
// 第二种,输出结果:2016-05-28 16:17:00<font color='#FF0000'></font>
consolelog(strreplace(/(<font>)(<\/font>)/g ,"$1$2"));
按需选择吧
自己试试吧:
<!doctype html public "-//w3c//dtd html 40 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="属性,样式,元素,写法,页面">
<meta 使用示例如下:var str = &quo">
<style>
body{
background-color:red;
}
divsel{
font-size:15px;
color:green;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
windowonload = function(){
var sheet =documentstyleSheets[0];
var rules = sheetcssRules || sheetrules;//
var rule = rules[0];
alert(ruleselectorText)
alert(rulestylecssText)
rule = rules[1];
alert(ruleselectorText)
alert(rulestylecssText)
}
//-->
</SCRIPT>
</head>
<body>
</body>
</html>
使用css控制页面有4种方式,分别为行内样式(内联样式)、内嵌式、链接式、导入式。
行内样式(内联样式)即写在html标签中的style属性中,如<div style="width:100px;height:100px;"></div>
内嵌样式即写在style标签中,例如<style type="text/css">div{width:100px; height:100px}</style>
链接式即为用link标签引入css文件,例如<link href="testcss" type="text/css" rel="stylesheet" />
导入式即为用import引入css文件,例如@import url("testcss")
如果想用javascript获取一个元素的样式信息,首先想到的应该是元素的style属性。但是元素的style属性仅仅代表了元素的内联样式,如果一个元素的部分样式信息写在内联样式中,一部分写在外部的css文件中,通过style属性是不能获取到元素的完整样式信息的。因此,需要使用元素的计算样式才获取元素的样式信息。
var keyword="";//关键字
这样写就可以:
var keyword=documentforms[0]keywordvalue;//关键字
但是,你的这样语句就是页面加载的时候执行一次,因为你写在onLoad里面的,那么当页面加载以后你修改keyword的值是没有效果的。
要能够多次执行,应该这样:
<html><head>
<script language="JavaScript">
function func()
{
var keyword=documentforms[0]keywordvalue;//关键字
var r=documentbodycreateTextRange();
var s='<font style="background-color: #FFFF00;">'+keyword+'</font>';
while(rfindText(keyword)){
for(var o=rparentElement();o&&otagName!="A";o=oparentElement);
if(!o)try{
rpasteHTML(s);
}catch(e){}
rcollapse(false);
}
return false;
}
</script>
</head><body>
<form onSubmit="return func();">
<input name='keyword' type='text' value="">
<input type=submit value='Search'>
</form>
</body></html>
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8>
<title>recursion</title>
<style type="text/css">
</style>
<script type="text/javascript">
var array = [];
onload = function ()
{
var tags = documentbodygetElementsByTagName ('');
for ( var i = 0; i < tagslength; i++)
{
arraypush (getText (tags[i]));
}
consolelog (array);
}
var getText = function (dom)
{
var index = 0, html = dominnerHTML;
while (domchildrenlength && index < domchildrenlength)
{
var chtml = domchildren[index]outerHTML;
html = dominnerHTMLreplace(chtml, '');
index++;
}
return "<font>" + html + "</font>";
}
</script>
</head>
<body>
<p>
ths is p<a href="">this is a</a>wyz
</p>
<i>this is i</i>
<b>this is b</b>
</body>
</html>
给你个参考:
var newStyle = documentcreateElement('style');
newStyleappendChild(documentcreateTextNode("\
@font-face {\
font-family: '" + yourFontName + "';\
src: url('" + yourFontURL + "') format(yourFontFormat);\
}\
"));
documentheadappendChild(newStyle);
获取的页面元素,就可以对页面元素的属性进行 *** 作,属性的 *** 作包括属性的读和写。
*** 作属性的方法
1、“” *** 作
2、“[ ]” *** 作
属性写法
1、html的属性和js里面属性写法一样
2、“class” 属性写成 “className”
3、“style” 属性里面的属性,有横杠的改成驼峰式,比如:“font-size”,改成”stylefontSize”
js *** 作属性
《script type=text/javascript》
widow。onload = function(){ 全部加载渲染完之后才执行下一步
document。getElementById(div1)。title= 我看到了;
《/script》
《body》
《div id = div1 class = div1 title = 这是一个div元素,你看到了吗?》
《/body》
在js中有类似font-size这类似的系统回默认为-号,可以用小驼峰 fontSize写法
class属性
需要在class后面加Name
中括号
需要在变量加上中括号。[color]写法
style的写法['style']
document。write 只能重绘整个页面
innerhtml 可以重绘页面的一部分。
以上就是关于JS 正则 替换font里的内容 2016-05-28 16:17:00<font color="#FF0000">4794</font> 次全部的内容,包括:JS 正则 替换font里的内容 2016-05-28 16:17:00<font color="#FF0000">4794</font> 次、怎么用JS获取到style标签里的内容、如何javascript获取css中的样式等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)