jQuery动态选择器 [英] jQuery dynamic selector

查看:80
本文介绍了jQuery动态选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码在循环中使用选择器.

I have some code which uses a selector in a loop.

这有效:

document.getElementById("new_grouping_"+i).value

这不是:$("#new_grouping_"+i).value

有没有一种使用jQuery的方法?

Is there a way to do this using jQuery?

推荐答案

您应使用 val()函数:

var myValue = $("#new_grouping_"+i).val(); // to get the value

$("#new_grouping_"+i).val("something");    // to set the value 

这篇关于jQuery动态选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆