2009-08-30 78 views

回答

1

当你拨打:

$(this).attr('tempref') 

返回一个值,不是jquery对象,所以你不能在这之后添加.val(),你不能用this来引用对象。如果要将该值赋给href属性,你必须做到:

$("a#link").each(function(){ 
    $(this).attr("href",$(this).val()); 
}) 

如果你不希望这样做,试图更好地解释你的问题。

+0

感谢它帮了我这么多 – GOM3A 2009-08-30 11:00:17

+0

@gomaa,如果这个答案帮了你,你可以点击左边的勾号来显示这是被接受的答案。 – nickf 2009-08-30 11:18:39

+0

尝试缓存'$(this)',因为它花费两倍的时间来调用'$(this)'两次。 – 2012-11-29 01:04:17

0

你并不需要调用VAL():

$("a#link").attr("href", $(this).attr('tempref')); 
0

感谢所有 我用这个代码,它工作正常

$("a").each(function() 
{ 
    if($(this).attr('tempref')!=null) 
    {  
     var tempref= $(this).attr('tempref'); 
    } 
    if(tempref!=null) 
    {  
     $(this).attr('href',tempref); 
    } 
}) 
相关问题