开发者

What is the most cheap way to mix `this` and other selectors in JQuery

开发者 https://www.devze.com 2023-01-29 13:29 出处:网络
what is the best way to mix this with other selectors in JQuery:filter,[id=\"\"] and stuff like this, lets assume we wanna read .val() of an input with name=\"input\" in form with that function is bin

what is the best way to mix this with other selectors in JQuery :filter,[id=""] and stuff like this, lets assume we wanna read .val() of an input with name="input" in form with that function is bind to it.

and if possible do they cost different ? if so why ?

here is the form

<form>
<input type="text" name="input">
</form>

like we have this

   $("form").submit(function(){

        if($(this).valid() == true){ //here  i wanna read the value of inp开发者_如何学运维ut with name test}


The selector would just be:

var myVal = $("#test input[name=input]").val();

The this version would use .find() like this:

var myVal = $(this).find("input[name=input]").val();

...which is faster depends on the browser and what it supports, namely if it supports querying by selectors relatively.


use find maybe?

0

精彩评论

暂无评论...
验证码 换一张
取 消