closest

Finding closest pair of points on a sphere

一曲冷凌霜 提交于 2019-11-29 21:03:39
问题 I know how to implement n log n closest pair of points algorithm (Shamos and Hoey) for 2D cases (x and y). However for a problem where latitude and longitude are given this approach cannot be used. The distance between two points is calculated using the haversine formula. I would like to know if there is some way to convert these latitudes and longitudes to their respective x and y coordinates and find the closest pair of points, or if there is another technique that can be used to do it. 回答1

jQuery: find input field closest to button

时光怂恿深爱的人放手 提交于 2019-11-28 09:44:42
I have a large HTML form with multiple input fields (one in each row). Among these I have several fields with a specific class that appear left from a button. There are no other buttons or fields in these rows so they only contain the field and button as below. How can I get the ID of such a field when clicking on the button right from it, i.e. closest to it ? All fields in question look like this: <input type="text" class="dateField" data-date-format="yyyy-mm-dd" id="field1" name="field1" /> All buttons in question look like this: <button type="button">Select Date</button> Thanks for any help

jQuery closest(); not working

家住魔仙堡 提交于 2019-11-28 08:24:45
I am trying to do make some text show when a text input is on focus, but the closest(); method doesn't seem to be working. I have done a JS Fiddle for you to look at. and here is the code also. JS $(document).ready(function(){ $('.validation-error').hide(); $('.name-input').on("focus", function(){ $(this).closest('.validation-error').show(); }); }); HTML <fieldset> <legend>User Details</legend> <table> <tr> <td width="200"> <label for="user"><span class="required-fields">*</span> User Name</label> </td> <td> <input type="text" id="user" class="name-input"> </td> <td> <p class="validation-error

using jquery, how would i find the closest match in an array, to a specified number

帅比萌擦擦* 提交于 2019-11-27 14:26:42
using jquery, how would i find the closest match in an array, to a specified number For example, you've got an array like this: 1, 3, 8, 10, 13, ... What number is closest to 4? 4 would return 3 2 would return 3 5 would return 3 6 would return 8 ive seen this done in many different languages, but not in jquery, is this possible to do simply You can use the jQuery.each method to loop the array, other than that it's just plain Javascript. Something like: var theArray = [ 1, 3, 8, 10, 13 ]; var goal = 4; var closest = null; $.each(theArray, function(){ if (closest == null || Math.abs(this - goal)

使用jquery获取父元素或父节点的方法

为君一笑 提交于 2019-11-27 06:57:15
jquery获取父元素 方法比较多,比如parent(),parents(),closest()这些都能帮你实现查找父元素或节点,下面我们来一一讲解: 先举个例子, 1. < ul class = "parent1" >   2. < li >< a href = "#" id = "item1" >jquery获取父节点</ a ></ li >   3. < li >< a href = "#" >jquery获取父元素</ a ></ li >   4. </ ul > 我们的目的是通过 id 为 item1 的便签a取到 class 为 parent1 的ul元素,有以下几种方法: 1、parent([expr]) 取得一个包含着所有匹配元素的唯一父元素的元素集合。 你可以使用可选的表达式来筛选。 代码如下 1. $( '#item1' ).parent().parent( '.parent1' ); 2、:parent 匹配含有子元素或者文本的元素 代码如下   1. $( 'li:parent' ); 3、parents([expr]) 取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素)。可以通过一个可选的表达式进行筛选。 代码如下    1. $( '#items' ).parents( '.parent1' );   4、 closest([expr])

jQuery: find input field closest to button

那年仲夏 提交于 2019-11-27 03:10:00
问题 I have a large HTML form with multiple input fields (one in each row). Among these I have several fields with a specific class that appear left from a button. There are no other buttons or fields in these rows so they only contain the field and button as below. How can I get the ID of such a field when clicking on the button right from it, i.e. closest to it ? All fields in question look like this: <input type="text" class="dateField" data-date-format="yyyy-mm-dd" id="field1" name="field1" />

jQuery closest(); not working

百般思念 提交于 2019-11-27 02:16:43
问题 I am trying to do make some text show when a text input is on focus, but the closest(); method doesn't seem to be working. I have done a JS Fiddle for you to look at. and here is the code also. JS $(document).ready(function(){ $('.validation-error').hide(); $('.name-input').on("focus", function(){ $(this).closest('.validation-error').show(); }); }); HTML <fieldset> <legend>User Details</legend> <table> <tr> <td width="200"> <label for="user"><span class="required-fields">*</span> User Name<

How do I find values close to a given value?

我是研究僧i 提交于 2019-11-27 02:12:00
问题 I have data = [1 1.2 1.3 1.5 1.8] I want to find closest values before and after from data for this point, b = 1.23 How do I do this? 回答1: Here is another method. The vector data need not be sorted and b can be positive or negative. [~,I] = min(abs(data-b)); c = data(I); 回答2: if the data is sorted you can use find: i_lower = find(data <= b,1,'last'); i_higher = find(data >= b,1,'first'); lower_than_b = data(i_lower) higher_than_b = data(i_higher) 回答3: How about min(abs(data - b)) ? 回答4: This