在类选择器中传递 jQuery this.id
Passing jQuery this.id in class selector
我有两个不同的输入字段,它使用typeahead。
在第一个字段中,我们输入国家/地区,在其他字段中,我们应该选择城市,具体取决于国家/地区。所以我正在制作一个javascript/jQuery函数,以传递字段ID,知道我选择了3对国家+城市对中的哪一对。
我正在使用
$('.demoTypeAhead').typeahead({
source: getCityForCountry($(this).id)
});
在函数 getCityForCountry 中,我想传递一个特定于字段的 id,但 $(this) 或这都不起作用,因为它返回整个 DOM 对象。
jQuery 对象没有 .id
属性。你要么想要
this.id // or
$(this).prop("id") // or even
$(this).attr("id")
$(this) 在此作用域上不会将输入作为对象返回,而是将整个页面作为对象返回...
刚刚为它做了jsfiddle: Jsfiddle
http://jsfiddle.net/s1d8nmqr/3/当我选择第一个输入时,我想重新加载 typeahead 的数据源以进行第二个输入(2 级选择)
相关文章:
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- jquery$(this)对象缺少问题
- jQuery$(this)引用未定义
- jQuery“this”范围问题
- jQuery(this) 目標不是找到元素
- jQuery $(this) inside function
- jQuery 'this' 跟随一个 .find click 函数
- 将jQuery$(this)转换为原始元素
- 在Meteor中使用Jquery$(this)
- Jquery this concatenation
- Jquery $this属性选择器是否包含单词
- 普通的JavaScript等于jquery $(this)
- jQuery this.href 字符串比较不起作用
- jQuery $this 在网页上不起作用
- jquery $(this).find 对我不起作用
- jQuery: $(this) vs. this.$()
- JQuery $(this) 在 ajax POST 之后无法访问
- jQuery $(this) 伪选择器
- jQuery this.data-x 不起作用
- Jquery - this.form不起作用