Which HTML Attribute do I hate the most? That is id
. I wrote this to avoid querying element by id.
This is a jQuery plugin to find the element matching a selector that is somewhere nearby :-)
Image a scenario of User Mobile Binding:
<form class="form-horizontal">
<div class="form-group">
<label class="col-xs-2 control-label" for="binding-mobile">
手机号码:
</label>
<div class="col-xs-9">
<input class="form-control" id="binding-mobile" type="tel" placeholder="手机号码"
name="mobile"/>
<input class="form-control" id="binding-smscode" placeholder="验证码"
name="smscode"/>
<button class="btn btn-link" type="button" id="js-smscode">
<span class="state normal">获取验证码</span>
<span class="state alter"><span class="code" data-bind="cooldown">0</span>秒后可重新获取</span>
</button>
</div>
</div>
</form>
Use Jquery Nearby to help you:
var $element=$("#js-smscode");//the base point of searching
$element.nearby(1); //equals to `.siblings(":eq(1)")`
$element.nearby("#binding-mobile");
$element.nearby('input[name="mobile"]');
$element.nearby("mobile"); // equals to `.nearby("[name=mobile]")`
The above all found #binding-mobile
element. Especially the .nearby(name)
form works gracefully,
Simple string parameter that test failed with /^#/
or /[.[>~:]/
is considered to name, EXCEPT:
body|form|select|input|textarea|div|span|h\d|table|tr|td|th|p|header|section|fieldset
Jquery Nearby find out the target through these steps:
.siblings(":eq()")
instead.#
then find global document. (Contains same id in one page is your fault :<).form-group
.form
context..dialog
context.document
. You can specify a searching order by the second parameter.$element.nearby("mobile", [".form","#myDialog"]);
So at last Jquery Nearby WON'T return undefined|null|false
, it returns EMPTY JQUERY object if found nothing.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型