我正在尝试获取HTML页面中每个元素的数组:
var elms = document.querySelectorAll("");
Run Code Online (Sandbox Code Playgroud)
但没有成功.
想法?
谢谢
我通过这种方式在文档的头部通过javascript注入一个样式:
var style = document.createElement("style");
document.head.appendChild(style);
style.innerHTML = "a, .left-hand { cursor:wait; }";
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法检查这种风格是否在文件中(考虑到其他风格)以及如何删除它.
谢谢
我有这段代码可以正常工作:
if (typeof jQuery === "undefined" || jQuery.fn.jquery !== '1.4.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src","http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
script_tag.onload = main; // Run main() once jQuery has loaded
script_tag.onreadystatechange = function () { // Same thing but for IE
if (this.readyState == 'complete' || this.readyState == 'loaded') main();
}
document.getElementsByTagName("head")[0].appendChild(script_tag);
} else {
main();
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试通过 bookmarkleter 压缩它时,出现“意外标识符”错误
javascript:(function(){if(typeof%20jQuery===%22undefined%22%20||%20jQuery.fn.jquery%20!=='1.4.2'){var%20script_tag=document.createElement('script');script_tag.setAttribute(%22type%22,%22text/javascript%22);script_tag.setAttribute(%22src%22,%22http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js%22);script_tag.onload=main;script_tag.onreadystatechange=function(){if(this.readyState=='complete'%20||%20this.readyState=='loaded')main();}document.getElementsByTagName(%22head%22)[0].appendChild(script_tag);}else{main();}})();
Run Code Online (Sandbox Code Playgroud)
建议?
谢谢
你好,我试图让这个音频停止,但我找不到任何办法这样做:
$('<audio id="elevator" autoplay loop preload="auto" autobuffer><source src="elevator.mp3" /><source src="elevator.ogg" /></audio>').appendTo('body');
$('#elevator').pause();
Run Code Online (Sandbox Code Playgroud) 我试图用 BeautifulSoup 包装标签的内容。这:
<div class="footnotes">
<p>Footnote 1</p>
<p>Footnote 2</p>
</div>
Run Code Online (Sandbox Code Playgroud)
应该变成这样:
<div class="footnotes">
<ol>
<p>Footnote 1</p>
<p>Footnote 2</p>
</ol>
</div>
Run Code Online (Sandbox Code Playgroud)
所以我使用以下代码:
footnotes = soup.findAll("div", { "class" : "footnotes" })
footnotes_contents = ''
new_ol = soup.new_tag("ol")
for content in footnotes[0].children:
new_tag = soup.new_tag(content)
new_ol.append(new_tag)
footnotes[0].clear()
footnotes[0].append(new_ol)
print footnotes[0]
Run Code Online (Sandbox Code Playgroud)
但我得到以下信息:
<div class="footnotes"><ol><
></
><<p>Footnote 1</p>></<p>Footnote 1</p>><
></
><<p>Footnote 2</p>></<p>Footnote 2</p>><
></
></ol></div>
Run Code Online (Sandbox Code Playgroud)
建议?
javascript ×3
arrays ×1
audio ×1
bookmarklet ×1
css ×1
html ×1
html5-audio ×1
jquery ×1
lxml ×1
python ×1