HTMLjavascript 文本 清除 CSS 样式 代码 等标签 如何编写

html-css015

HTMLjavascript 文本 清除 CSS 样式 代码 等标签 如何编写,第1张

1.</?font[^><]*>这个只却掉font标签的, 保留除font以外的所有标签, 如<img><p>等等. 同样的你需要去掉其他标签, 只需要将里面的font换你要去掉的;

2.</?[^/?(img)|(p)][^><]*>这个保留(这里我写的保留了img, p这两个标签)你指定的标签,其他的(包括font)全去掉, 如果你还有其他的标签想保留, 直接在里面加一个 |(xxx);

3.</?[a-zA-Z]+[^><]*>这个表达式可以去掉所有HTML的标签;

4.JAVA代码可以这样写:

public static String delTagsFContent(String content){

String patternTag = "</?[a-zA-Z]+[^><]*>"

String patternBlank = "(^\\s*)|(\\s*$)"

return content.replaceAll(patternTag, "").replaceAll(patternBlank, "")

}

清除所有默认样式的css代码:

html, body, div, span, applet, object, iframe,

h1, h2, h3, h4, h5, h6, p, blockquote, pre,

a, abbr, acronym, address, big, cite, code,

del, dfn, em, font, img, ins, kbd, q, s, samp,

small, strike, strong, sub, sup, tt, var,

初始化代码(清除CSS代码):

ul,li{ padding:0margin:0list-style:none}

解析清除ul li样式代码:

相等于分别对ul和li设置padding:0margin:0list-style:none;

padding:0 —— 设置内补白(对象内间距)为0

margin:0 —— 设置对象外间距为0

list-style:none —— 去除自带无序圆点

HTML/javascript

引用外部文件中的js脚本,

<script type="text/javascript" src="ext.js"></script>也可以象下面这样写,language不是必要的,但是推荐上面的写法;

<script language="javascript" type="text/javascript" src="ext.js"></script>

页面内引用:

<script type="text/javascript">//<![CDATA[var x = 0function fn(args) { //...} //]]></script>加上“//<![CDATA[” 和 “//]]>”是为了兼容XHTML,是推荐的写法,HTML时代一般用“<!--”和“//-->”

在一些HTML控件的事件属性中使用(一般事件为onxxx,如onmouseover,onclick,onchange)

<body onload="alert('loaded')"><input type="text" name="username" onclick="alert(this.value)" />在一些HTML控件的非事件属性中使用(注意:一定要加javascript:)

<a href="javascript:void(0)" onclick="alert(this.innerText)">my blog:http://blog.csdn.net/kimsoft</a>

变通一下就好了,如果写JQuery有难度,那不妨换个解决方法,有img算特例,给有img的a标签加上特有类,比如

<a class="hasimg"><img .../></a>

这样处理,可能要容易许多,即使你坚持用JQuery增加样式。

回到你的预设:用jQuery父元素选择器应该可以解决你的难题。希望你的HTML代码不是真的连一个ID属性(或者class属性)都没有——真这样的话就算是JQuery也会"累死"的。

// 假设要添加的给含img的<a>的类为'noBorder',且有多个这样的元素,则:

$(function(){

    $('a>img').each(function (e){      //a>img 可能污染严重,记得加以限制。

        var eparent = $(this).parent()// 类型:数组

        $(eparent[0]).addClass('noBorder')

    })

})

/** 清除内外边距 **/

body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, /* structural elements 结构元素 */

dl, dt, dd, ul, ol, li, /* list elements 列表元素 */

pre, /* text formatting elements 文本格式元素 */

form, fieldset, legend, button, input, textarea, /* form elements 表单元素 */

th, td /* table elements 表格元素 */ {

    margin: 0

    padding: 0

}

/** 设置默认字体 **/

body,

button, input, select, textarea /* for ie */ {

    font: 14px/1.5 tahoma, \5b8b\4f53, sans-serif

}

h1, h2, h3, h4, h5, h6 { font-size: 100% font-weight: normal}

address, cite, dfn, em, var { font-style: normal } /* 将斜体扶正 */

code, kbd, pre, samp { font-family: courier new, courier, monospace } /* 统一等宽字体 */

small { font-size: 12px } /* 小于 12px 的中文很难阅读, 让 small 正常化 */

/** 重置列表元素 **/

ul, ol { list-style: none }

/** 重置文本格式元素 **/

a { text-decoration: none }

a:hover { text-decoration: underline }

sup { vertical-align: text-top } /* 重置, 减少对行高的影响 */

sub { vertical-align: text-bottom }

/** 重置表单元素 **/

legend { color: #000 } /* for ie6 */

fieldset, img { border: 0 } /* img 搭车:让链接里的 img 无边框 */

button, input, select, textarea { font-size: 100% } /* 使得表单元素在 ie 下能继承字体大小 */

/* 注:optgroup 无法扶正 */

/** 重置表格元素 **/

table { border-collapse: collapse border-spacing: 0 }

/* 重置 HTML5 元素 */

article, aside, details, figcaption, figure, footer,header, hgroup, menu, nav, section,

summary, time, mark, audio, video {

    display: block

    margin: 0

    padding: 0

}

mark { background: #ff0 }

理念:

1. reset 的目的不是清除浏览器的默认样式, 这仅是部分工作. 清除和重置是紧密不可分的.

2. reset 的目的不是让默认样式在所有浏览器下一致, 而是减少默认样式有可能带来的问题.

3. reset 期望提供一套普适通用的基础样式. 但没有银弹, 推荐根据具体需求, 裁剪和修改后再使用.