range

Get all DOM block elements for selected texts

孤街醉人 提交于 2019-11-27 19:32:04
When selecting texts in HTML documents, one can start from within one DOM element to another element, possibly passing over several other elements on the way. Using DOM API, it is possible to get the range of the selection, the selected texts, and even the parent element of all those selected DOM elements (using commonAncestorContainer or parentElement() based on the used browser). However, there is no way I am aware of that can list all those containing elements of the selected texts other than getting the single parent element that contains them all. Using the parent and traversing the

How to convert sequence of numbers in an array to range of numbers

梦想与她 提交于 2019-11-27 19:04:41
In javascript how to convert sequence of numbers in an array to range of numbers? eg. [2,3,4,5,10,18,19,20] to [2-5,10,18-20] CMS Here is an algorithm that I made some time ago , originally written for C#, now I ported it to JavaScript: function getRanges(array) { var ranges = [], rstart, rend; for (var i = 0; i < array.length; i++) { rstart = array[i]; rend = rstart; while (array[i + 1] - array[i] == 1) { rend = array[i + 1]; // increment the index if the numbers sequential i++; } ranges.push(rstart == rend ? rstart+'' : rstart + '-' + rend); } return ranges; } getRanges([2,3,4,5,10,18,19,20]

Select range in contenteditable div

六眼飞鱼酱① 提交于 2019-11-27 18:49:31
I've got a contenteditable div and a few paragraphs in it. Here's my code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <div id="main" contenteditable="true" style="border:solid 1px black; width:300px; height:300px"> <div>Hello world!</div> <div> <br> </div> <div>This is a paragraph</div> </div> </body> </html> Assuming, I want to make a range selection which will contain the string "world! This is" How to do that? Once you've got hold of the text nodes containing the text you want highlighted, it's easy. How you get those

html - selection range - getting the range + starting node + ending node + distance

爷,独闯天下 提交于 2019-11-27 18:05:08
问题 From my previous question for selecting specific html text, I have gone through this link to understand range in html string. For selecting a specific text on html page. We need to follow this steps. Assumed HTML: <h4 id="entry1196"><a href="http://radar.oreilly.com/archives/2007/03/call_for_a_blog_1.html" class="external">Call for a Blogger's Code of Conduct</a></h4> <p>Tim O'Reilly calls for a Blogger Code of Conduct. His proposals are:</p> <ol> <li>Take responsibility not just for your own

How to check if an integer is within a range of numbers in PHP?

て烟熏妆下的殇ゞ 提交于 2019-11-27 17:48:16
How can I check if a given number is within a range of numbers? Dancrumb The expression: ($min <= $value) && ($value <= $max) will be true if $value is between $min and $max , inclusively See the PHP docs for more on comparison operators Gordon You can use filter_var filter_var( $yourInteger, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => $min, 'max_range' => $max ) ) ); This will also allow you to specify whether you want to allow octal and hex notation of integers . Note that the function is type-safe. 5.5 is not an integer but a float and will not validate. Detailed tutorial

contenteditable div backspace and deleting text node problems

旧街凉风 提交于 2019-11-27 17:45:16
There are so many issues with contenteditable divs and deleting html and/or non content editable content inside editable divs. Using an answer by the excellent Tim Down here: How to delete an HTML element inside a div with attribute contentEditable? Using Tim's code, the entire text node gets deleted. I need this to work like any textarea would, deleting character by character and just making sure html elements can be backspaced as well. I tried the following else if(node){ var index = node.length-1; if(index >= 0) node.deleteData(index,1); else this.removeChild(node); } But this is obviously

Python: Checking to which bin a value belongs

半腔热情 提交于 2019-11-27 16:18:06
问题 I have a list of values and a list of bin edges. Now I need to check for all values to what bin they belong to. Is there a more pythonic way than iterating over the values and then over the bins and checking if the value belongs to the current bin, like: my_list = [3,2,56,4,32,4,7,88,4,3,4] bins = [0,20,40,60,80,100] for i in my_list: for j in range(len(bins)): if bins(j) < i < bins(j+1): DO SOMETHING This doesn't look very pretty to me. Thanks! 回答1: Probably too late, but for future

MySQL display all date in between range [duplicate]

二次信任 提交于 2019-11-27 16:16:24
This question already has an answer here: generate days from date range 28 answers I want to display all dates between a from and to dates from MySQL. For example the data from schedule table that has from and to fields are: from date is 2013-3-13 , and to date is 2013-3-20 , my desired result is: 2013-3-13 2013-3-14 2013-3-15 2013-3-16 2013-3-17 2013-3-18 2013-3-19 2013-3-20 How can I achieve this using MySQL query only (without having to use stored procedure 'cause I'm not familiar with it)? EDIT: The answer here is very helpful, though I still don't fully get what is desired. In this sample

Is there a way in Matlab using the pseudo number generator to generate numbers within a specific range?

末鹿安然 提交于 2019-11-27 16:13:41
For example: round(7*rand(1,5)) Generates 5 numbers between 1 and 7 Is there a way to generate 5 random numbers between 5 and 7? Or an abstraction of that? More generally: minInt = 5; maxInt = 7; numInts = 10; r = randi([minInt, maxInt],[1,numInts]) r = 6 7 7 7 6 5 5 5 7 5 gnovice First, if you are wanting to generate random integer values, it's better to use the function RANDI . Then it's just a matter of shifting and scaling the random numbers accordingly. The following should give you random integers between 5 and 7 inclusive: nums = randi(3,[1 5])+4; EDIT: As Amro's comment and Doug's

Multiplication of two integers in C++

女生的网名这么多〃 提交于 2019-11-27 16:00:51
I have a pretty basic question, but I am not sure if I understand the concept or not. Suppose we have: int a = 1000000; int b = 1000000; long long c = a * b; When I run this, c shows negative value, so I changed also a and b to long long and then everything was fine. So why do I have to change a and b , when their values are in range of int and their product is assigned to c (which is long long )? I am using C/C++ The int s are not promoted to long long before multiplication, they remain int s and the product as well. Then the product is cast to long long , but too late, overflow has struck.