jQuery从元素内选择 [英] jquery select from within element

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

问题描述

我该怎么做(但以一种可行的方式):

How do I do this (but in a way that works):

$("MyElem").get("[id$='Date']").datepicker();

基本上,我正在尝试在给定的父元素的上下文中选择id中所有以单词"Date"结尾的元素.

Essentially I'm trying to select all elements that end with the word "Date" in the id within the context of a given parent element.

因此,这应该解释为:

  1. 获取"MyElem".
  2. 从"MyElem"中递归搜索所有子级,并找到以"Date"结尾的id.
  3. 对于第2步结果中的每个项目,请在该元素上调用datepicker

推荐答案

为什么不使用find方法:

$('#myelem').find('[id&=Date]').datepicker();

或者为什么不使用更好的选择器:

Or why not using a better selector:

$('#myelem *[id$=Date]').datepicker();

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

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