无法识别奇怪的查询语法

时间:2014-05-15 10:09:30

标签: jquery html

我是jquery的新手。我当前的项目应用程序是使用ajax和jquery构建的。 我在项目中找到了一行代码

$("#p" + this.selected).attr("class", "current");

它意味着什么? “#p”表示ID 但是“#p”+ this.selected是什么意思?

2 个答案:

答案 0 :(得分:1)

它正在连接id。

实施例

var selectedValue="test";

$("#P"+selectedValue)

相当于,

$("#Ptest")

答案 1 :(得分:1)

$("#p" + this.selected).attr("class", "current");

在上面的代码中,$("#p" + this.selected)是一个jQuery选择器,其中jQuery选择匹配id = "#p" + this.selected的元素(而this.selected是当前元素的选定值,因为它引用当前元素的实例被调用的代码)

.attr("class", "current");是将元素的类属性(id = "#p" + this.selected)更改为“当前”。

有关详细信息,请参阅"jQuery Selectors"

相关问题