相关疑难解决方法(0)

使用Javascript/jQuery从HTML元素中获取所有属性

我想将一个Html元素中的所有属性放入一个数组:就像我有一个jQuery对象,其中html如下所示:

<span name="test" message="test2"></span>
Run Code Online (Sandbox Code Playgroud)

现在一种方法是使用这里描述的xml解析器,但后来我需要知道如何获取我的对象的html代码.

另一种方法是使用jquery,但如何?属性的数量和名称是通用的.

谢谢

顺便说一句:我无法使用document.getelementbyid或类似的东西访问该元素.

javascript jquery parsing attributes

160
推荐指数
9
解决办法
24万
查看次数

删除所有属性

是否可以使用jQuery一次删除所有属性?

<img src="example.jpg" width="100" height="100">
Run Code Online (Sandbox Code Playgroud)

<img>
Run Code Online (Sandbox Code Playgroud)

我试着$('img').removeAttr('*');没有运气.任何人?

javascript jquery

36
推荐指数
4
解决办法
5万
查看次数

使用正则表达式删除所有 html 属性(替换)

例如我有这样的html:

\n\n
<title>Ololo - text\xe2\x80\x99s life</title><div class="page-wrap"><div class="ng-scope"><div class="modal custom article ng-scope in" id="new-article" aria-hidden="false" style="display: block;"><div class="modal-dialog first-modal-wrapper">< div class="modal-content"><div class="modal-body full long"><div class="form-group">olololo<ul style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);"><li>texttext</li><li>Filter the events lists by host.</li><li>Create graphs for separate hosts and for the groups of hosts.</li></ul><p style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);">bbcvbcvbcvbcvbcvbcvbcvb</p></div></div></div></div></div></div><title>cvbcbcvbcvbcvbccb</title><div class="page-wrap"></div></div>\n
Run Code Online (Sandbox Code Playgroud)\n\n

我怎样才能从这样的html中删除所有样式类id等?

\n\n

我有这样的正则表达式:

\n\n
/<([a-z][a-z0-9]*)[^>]*?(\\/?)>/i\n
Run Code Online (Sandbox Code Playgroud)\n\n

怎么了?如何借助正则表达式删除所有html属性?

\n\n

这是小提琴:

\n\n

http://jsfiddle.net/qL4maxn0/1/

\n

html javascript regex

1
推荐指数
1
解决办法
5780
查看次数

标签 统计

javascript ×3

jquery ×2

attributes ×1

html ×1

parsing ×1

regex ×1