⑴ jquery 取元素内容 怎么 排除span标签
<!DOCTYPEHTML>
<html>
<head>
<metacharset=UTF-8/>
<title>Nothing</title>
<styletype="text/css">
</style>
<scripttype="text/javascript"src="jquery-1.8.0.min.js"></script>
<script>
$(function()
{
$(".").bind("click",function()
{
vartest=$($(this).prop('previousSibling')).text();
console.log(test);
})
})
</script>
</head>
<body>
<table>
<tr>
<td>6666<spanclass="">[复制]</span></td>
<td><span>6666</span><spanclass="">[复制]</span>
</td>
</tr>
</table>
</body>
</html>
⑵ jquery text()识别标签
text()方法只能输出文本:
例如:$('body').text('<a herf="#">下载</a>');这样子做的话 会输出整个a标签代码的
请使用html()方法;例如:$('body').html('<a herf="#">下载</a>');//这样就能输出可点击的a标签
⑶ jquery 清除文本含a标签及内容
$("a").remove()
⑷ jquery 如何去除标签内容的部分内容
参考思路:
取到div对象,然后遍历child,如果tagName不是文本的话删除。
参考代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
function test() {
var $children = $("#divTest").children();
$("#divTest").empty().append($children);
}
</script>
</head>
<body>
<div id="divTest" >abcd<span>test</span><a href="#">test</a></div>
<br /><br />
<input type="button" onclick="test()" value="去掉div中的abcd" />
</body>
</html>
⑸ js如何过滤div内某特定HTML标签
//这里为了方便使用jQuery
//移除使用tag类的div标记下的strong标记下a标记下没有子回元素(链接为空答)的节点元素
jQuery('div.tagstronga:empty').parent().remove();
⑹ jquery :contains(“text”)是选取文本内容为“text”的元素 要是选
<!DOCTYPEhtml>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=UTF-8">
<scriptclass="jquerylibrary"src="/js/sandbox/jquery/jquery-1.8.2.min.js"type="text/javascript"></script>
<title>
RunJS演示代码
</title>
<script>
$(function(){
$("div:not(:contains('text'))").each(function(i,dom){
console.log(dom);
})
});
</script>
</head>
<body>
<div>
ddd
</div>
<div>
text
</div>
<div>
aa
</div>
</body>
</html>
⑺ 如何使用js正则 过滤某一个html标签下所有的标签跟样式呢只保留出纯文本
js过滤标签的方法。分享给大家供大家参考,具体如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>无标题文档</title>
<script>
window.onload=function()
{
varoTxt1=document.getElementById('txt1');
varoTxt2=document.getElementById('txt2');
varoBtn=document.getElementById('btn');
oBtn.onclick=function()
{
varreg=/<[^<>]+>/g;
oTxt2.value=oTxt1.value.replace(reg,'');
};
};
</script>
</head>
<body>
<textareaid="txt1"cols="40"rows="10"></textarea><br/>
<inputtype="button"value="过滤"id="btn"/><br/>
<textareaid="txt2"cols="40"rows="10"></textarea>
</body>
</html>
⑻ 怎么用js或者jQuery去除掉某个标签但是不去除里面的内容
1、可以使用正则直接取到img
//思路分两步:
//1,匹配出图片img标签(即匹配出所有图片),过滤其他不需要的字符
//2.从匹配出来的结果(img标签中)循环匹配出图片地址(即src属性)
varstr="<td>thisisteststring<imgsrc="http:yourweb.com/test.jpg"width='50'>123andtheend<imgsrc="所有地址也能匹配.jpg"/>33!<imgsrc="/uploads/attached/image/20120426/20120426225658_92565.png"alt=""/></td>"
//匹配图片(g表示匹配所有结果i表示区分大小写)
varimgReg=/<img.*?(?:>|/>)/gi;
//匹配src属性
varsrcReg=/src=['"]?([^'"]*)['"]?/i;
vararr=str.match(imgReg);
alert('所有已成功匹配图片的数组:'+arr);
for(vari=0;i<arr.length;i++){
varsrc=arr[i].match(srcReg);
//获取图片地址
if(src[1]){
alert('已匹配的图片地址'+(i+1)+':'+src[1]);
}
//当然你也可以替换src属性
if(src[0]){
vart=src[0].replace(/src/i,"href");
//alert(t);
}
}
⑼ 如何用jquery获得input type=text标签中value的值
</style>
<script type="text/javascript">
$(document).ready(function(){
alert($("input[type|='text']").val()); // 《--
})
</script>
</head>
<body>
<div id="box">
<input type="text" value="getValute">
</div>
⑽ jQuery 过滤html标签属性的特殊字符
您好,如果在表单中需要提交一字符串,其中包含,< > " &字符时,当我们把这字符串显示到jsp页面时,会和html标签产生冲突,导致web页面的某些部分消失或者格式不正确。为了解决以上问题,需要在显示之前,对字符串进行代码过滤。
把字符串中的 < 替换为 &It;
> 替换为 >
" 替换为 "
& 替换为 &
这里给出一个静态的过滤代码,供大家参考:
public class StringUtils {
/**
* This method takes a string which may contain HTML tags (ie, <b>,
* <table>, etc) and converts the '<'' and '>' characters to their HTML escape sequences.
* @param input the text to be converted.
* @return the input string with the characters '<' and '>' replaced with their HTML escape sequences.
*/
public static final String escapeHTMLTags(String input) {
//Check if the string is null or zero length -- if so, return
//what was sent in.
if (input == null || input.length() == 0) {
return input;
}
//Use a StringBuffer in lieu of String concatenation -- it is
//much more efficient this way.
StringBuffer buf = new StringBuffer(input.length());
char ch = ' ';
for (int i = 0; i < input.length(); i++) {
ch = input.charAt(i);
if (ch == '<') {
buf.append("<");
}
else if (ch == '>') {
buf.append(">");
}else if(ch == '"'){
buf.append(""");
}else if(ch == '&'){
buf.append("&");
}
else {
buf.append(ch);
}
}
return buf.toString();
}
}
此时,只需在jsp中对字符串调用此方法(StringUtils.escapeHTMLTags(str))即可。