jquery通过ID获取对象加数组下标0表示什么

jquery通过ID获取对象加数组下标0表示什么,第1张

因为jq选择器返回的是一个类数组对象,而[0] 表示这个对象的第一个元素,其实就是获取到的js dom对象,在你这条代码里面就是id='goods_number_'+resultrec_id的html元素

分别使用javascript原生的方法和jquery方法

<select id="test" name="">

<option value="1">text1</option>

<option value="2">text2</option>

</select>

code:

一:javascript原生的方法

1:拿到select对象: var myselect=documentgetElementById("test");

2:拿到选中项的索引:var index=myselectselectedIndex ; // selectedIndex代表的是你所选中项的index

3:拿到选中项options的value: myselectoptions[index]value;

4:拿到选中项options的text: myselectoptions[index]text;

二:jquery方法(前提是已经加载了jquery库)

1:var options=$("#test option:selected"); //获取选中的项

2:alert(optionsval()); //拿到选中项的值

3:alert(optionstext()); //拿到选中项的文本

<div class="foo">1111111</div>

<div class="foo">2222222</div>

<div class="foo">3333333</div>

<div class="foo">4444444</div>

$("divfoo")click(function(){

var t=$("divfoo")index(this);

alert(t);

});

$(function(){

    $("sy-tj-on")on('click','sy-tj-in',function(){

        consolelog($(this)index());

    })

})

type应该是button吧?用index,很方便,如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" ">

以上就是关于jquery通过ID获取对象加数组下标0表示什么全部的内容,包括:jquery通过ID获取对象加数组下标0表示什么、如何获取下拉列表选中的值 jquery、jquery如何实现 class相同的div 通过点击 获取div下标等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9314374.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存