elem

JS--通过按钮直接把input或者textarea里的值复制到粘贴板里

有些话、适合烂在心里 提交于 2019-12-03 20:54:13
function copyToClipboard(elem) { // create hidden text element, if it doesn't already exist var targetId = "_hiddenCopyText_" ; var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA" ; var origSelectionStart, origSelectionEnd; if (isInput) { // can just use the original source element for the selection and copy target = elem; origSelectionStart = elem.selectionStart; origSelectionEnd = elem.selectionEnd; } else { // must use a temporary form element for the selection and copy target = document.getElementById(targetId); if (!target) { var target = document.createElement(

pythonic-迭代器函数-itertools

倾然丶 夕夏残阳落幕 提交于 2019-12-03 12:22:52
认识 Python 的itertools模块提供了很多 节省内存的高效迭代器 , 尤其解决了一些关于数据量太大而导致 内存溢出(outofmemory) 的场景. 我们平时用的循环绝大多数是这样的. # while 循环: 求1+2+...100 s, i = 0, 1 while i <= 100: s += i i += 1 print('while-loop: the some of 1+2+..100 is:', s) # for 循环 s = 0 for i in range(101): s += i print('for-loop: the some of 1+2+..100 is:', s) while-loop: the some of 1+2+..100 is: 5050 for-loop: the some of 1+2+..100 is: 5050 但如果数据量特别大的话就凉凉了, 所以引入了itertools,迭代器, 类似于 懒加载 的思想 常用API chain() groupby() accumulate() compress() takewhile() islice() repeat() chain 拼接元素 把一组迭代对象串联起来,形成一个更大的迭代器: # join / split s = "If you please draw me a

Javascript: How to check if element is visible?

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i'm using the lightweight zepto.js framework and now I need to test if an element on the page is visible or not … this my case: A button triggers the function show_guides() . function show_guides() { $('#guides').toggle(); if ( $('#guides').is(':visible') ) { // does not work //$.cookie('guides_visible', 'true'); console.log("visible"); } else { console.log("invisible"); //$.cookie('guides_visible', null); } } If the $('#guides') are visible I want to save a cookie and if they are not I want to get rid of it. However zepto.js doesn't support

Web scrapping with a double loop with selenium and using By.SELECTOR

匿名 (未验证) 提交于 2019-12-03 09:06:55
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to get the pdf files from this website. I am trying to create a double loop so I can scroll over the years (Season) to get all the main pdf located in each year. The line of code is not working is this one. The problem is, I can not make this line work (The one that is supposed to loop all over the years (Season) : for year in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "#season a aria-valuetext"))): year.click() This is the full code: os.chdir("C:..") driver = webdriver.Chrome("chromedriver.exe") wait =

change data-attribute using jquery

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I change <div data-300=""></div> to <div data-500=""></div> using jquery? I don't want to remove the attribute and replace it as it contains data I need I just need to change the '300' to '500'. 回答1: Not generic at all, but it should do the job var $target = $('div[data-300]'), oldData = $target.data('300'); $target.removeAttr('data-300').attr({ 'data-500': oldData }); 回答2: Here's a function you can use: function attrChangeName(elem, attr, new_attr) { var data = $(elem).attr(attr); $(elem).attr(new_attr, data); $(elem).removeAttr

Enabling word wrap in a JTextPane with HTMLDocument

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Everywhere I read answers of people finding ways of enabling word wrapping in a JTextPane , but none of them work for me. I'm using an HTMLDocument (to display "text/html" content) and nothing that I have found so far got it to work. The JTextPane always cause the JScrollPane to scroll horizontally. I need the JTextPane to be scrollable, but only vertically. Would anyone have a workable demo of a word wrapping JTextPane displaying HTML content? 回答1: Use this as example to implement custom wrap (whatever you need) http://java-sl.com/tip_html

Processing XML in Python with ElementTree

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a problem with ElementTree.iter(). So I tried this example in this link : http://eli.thegreenplace.net/2012/03/15/processing-xml-in-python-with-elementtree/ So here's what I've tried: import elementtree.ElementTree as ET tree = ET.parse('XML_file.xml') root = tree.getroot() for elem in tree.iter(): print elem.tag, elem.attrib And I get this error AttributeError: ElementTree instance has no attribute 'iter' Additional info: The version of my Python is 2.4 I separately installed elementtree. Other examples in the link that I provide is

How to get the height of a DIV considering inner element&#039;s margins?

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider de following markup: <div id="outerElement"> <div id="innerElement" style="border: 1px solid blue; background-color: #f0f3f5; margin-top: 100px"> TESTE </div> </div> I want to get the actual final height of outerElement using javascript . I noticed that if I remove the vertical margins from innerElement I am able to get what I want but I cannot alter styles from within the outerElement . How do I do this? Obs: I already tried height, scrollheight and offsetHeight in all browsers. Chrome gives me the expected value (including inner

How to set default value of a slot as NULL in R?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to R. I'm trying to define a class similar to a tree node, that is , it has a left node and right node, which should be of the same class as the parent node. So I define the class as follows: setClass('Node', representation=(left='Node',right='Node', ...)) I want to set the default value of Node to be NULL by setting a prototype, but R says the following: invalid class "Node" object: invalid object for slot "left" in class "bicluster": got class "NULL", should be or extend class "Node" But if I don't speficy the default value to be

leetcode——155. 最小栈

不打扰是莪最后的温柔 提交于 2019-12-03 07:10:13
class MinStack(object): def __init__(self): """ initialize your data structure here. """ self._elem=[] def push(self, x): """ :type x: int :rtype: None """ self._elem.append(x) def pop(self): """ :rtype: None """ return self._elem.pop() def top(self): """ :rtype: int """ return self._elem[-1] def getMin(self): """ :rtype: int """ return min(self._elem) # Your MinStack object will be instantiated and called as such: # obj = MinStack() # obj.push(x) # obj.pop() # param_3 = obj.top() # param_4 = obj.getMin() 执行用时 :660 ms, 在所有 python 提交中击败了24.93%的用户 内存消耗 :15.5 MB, 在所有 python 提交中击败了19.17%的用户 ——2019