【发布时间】:2013-06-02 10:26:33
【问题描述】:
我有一个应该发送私人消息的每个循环:
[...].each(function () { $.get('board.php?func=list&id=' + (this.text) + '&send=Please read the board rules'); });
当我执行 'alert(this.text);'在每个循环中,一切正常。但是当我将它与获取请求的字符串连接时,它不起作用。 我错过了什么吗?
【问题讨论】:
-
this到底是什么,告诉我们它的使用范围?如果是元素,应该是$(this).text() -
尝试单独定义 url 并记录它以查看错误所在,例如
[...].each(function () { var url = 'board.php?func=list&id=' + (this.text) + '&send=Please read the board rules'; console.log(url); $.get(url); }); -
@adeneo:我正在使用的数据来自另一个获取请求。我现在在回调函数中工作:$(data from get request).find('#boardmembers').children('members').each[...]。其余的在上面;)
-
然后你正在处理元素,并且在 each()
this内部将是一个本机 DOM 元素,它没有text属性,你应该使用$(this).text()来获取文本,你试过了吗?
标签: jquery get concatenation each