jQuery('span[itemprop="telephone"]').append(jQuery('.top-telephone'));
在你的代码使用Attribute Equals Selector
。用于选择具有指定属性的元素。
属性等于选择器:选择具有指定属性的元素,其值恰好等于某个值。
通过此代码jQuery('span[itemprop="telephone"]')
,您可以选择具有属性itemprop
和telephone
值的元素。
Read about attribute Equals Selector
但在你的情况下,要附加到元素的属性。为此,您可以使用jquery .attr()
或.prop()
。
试试这个: -
jQuery('.top-telephone span').prop('itemprop', 'telephone');
$('.top-telephone span').prop('itemprop','telephone');
OR
jQuery('.top-telephone span').attr('itemprop', 'telephone');
$('.top-telephone span').attr('itemprop','telephone');
OR
jQuery('.top-telephone').find('span').attr('itemprop', 'telephone');
$('.top-telephone').find('span').attr('itemprop','telephone');
Jquery .attr()
Jquery .prop()
真棒,这工作正常:) 'jQuery('。top-telephone span')。attr('itemprop','telephone');'' – iamchriswick