这是一个代码:
<input type="button" id="array[1]" value="Value1" />
<input type="button" id="array[2]" value="Value2" />
<input type="button" id="array[3]" value="Value3" />
我想做这样的事情:
$('#array').click(function() {
id = this.id;
$.ajax({
here goes type, url, data and else
});
})
我想id
添加数组的编号。例如,如果我单击 id 为 array[3] 的按钮,那么 id 在 Jquery 函数中的值为 3。希望你明白我的意思。
最佳答案
首先,您不应该在 id 值中使用 []
...只能使用 a-zA-Z0-9-_.:
看html ID attribute有关规范的更多信息..
您应该将它们命名为 id_1
并使用正则表达式提取数字,就像其他答案所建议的那样......
(请记住,id 值不能仅以数字 a-zA-Z 开头)
关于php - 在 Jquery 中使用数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2939346/