【发布时间】:2012-05-02 18:33:06
【问题描述】:
我正在尝试检查所有链接并更改断开链接字段的背景颜色。 这是我的功能
function CheckLinks(){
$('#new_post_links_table tbody>tr').find("input").each(function() {
UrlExists($(this).val(), function(status){
if(status === 404){
$(this).css('background-color','#FC0');
}
}); });}
输入字段如下所示:
<table id="new_post_links_table">
...
<td><input type="text" name="mp3_link[]"/></td>
<td><input type="text" name="mp4_link[]"/></td>
</tr>
</tbody>
</table>
由于某种原因,css 没有应用。
注意:除了$(this).css... 部分外,我的 CheckLinks 功能确实有效。 (萤火虫)
注意:行是动态添加的
编辑:这是功能:
function UrlExists(url, cb){
jQuery.ajax({
url: url,
dataType: 'text',
type: 'GET',
complete: function(xhr){
if(typeof cb === 'function')
cb.apply(this, [xhr.status]);
}
});
}
【问题讨论】:
-
不,你的
UrlExists()函数的第一个参数有$(this).val,而它应该有$(this).val()。 -
那么这是一个参考问题。你最里面的
this没有映射到当前正在测试的元素。