[英]i want to get the attribute value to the same element
我使用了這行代碼,但是沒有用
$("a#link").attr("href",$(this).attr('tempref').val());
你打電話時:
$(this).attr('tempref')
它返回的值不是jquery對象,因此您不能在此之后添加.val(),也不能以此引用該對象。 如果要將值分配給href屬性,則必須執行以下操作:
$("a#link").each(function(){
$(this).attr("href",$(this).val());
})
如果您不想這樣做,請嘗試更好地解釋您的問題。
您不需要調用val():
$("a#link").attr("href", $(this).attr('tempref'));
謝謝所有我使用此代碼,它工作正常
$("a").each(function()
{
if($(this).attr('tempref')!=null)
{
var tempref= $(this).attr('tempref');
}
if(tempref!=null)
{
$(this).attr('href',tempref);
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.