2 回答
TA贡献1824条经验 获得超8个赞
在 razor AdsComponent 中是这样的。
<h3>AdsComponent</h3>
<div>
@Ads
</div>
@code {
private RenderFragment Ads
{
get
{
RenderFragment form = b =>
{
b.OpenElement(0, "script");
b.AddAttribute(0, "async", true);
b.AddAttribute(0, "src", "https://pagead2/googlesyndication.com/pagead/js/adsbygoogle.js");
b.CloseElement();
b.OpenElement(0, "ins");
b.AddAttribute(0, "class", "adsbygoogle");
b.AddAttribute(1, "style", "display:inline-block;width:728px;height:90px");
b.AddAttribute(2, "data-ad-client", "ca-pub-988649660289431");
b.AddAttribute(3, "data-ad-slot", "4069520508");
//Test
b.AddAttribute(4, "data-adtest", "on");
b.CloseElement();
b.OpenElement(0, "script");
b.AddContent(0, "(adsbygoogle = window.adsbygoogle || []).push({});");
b.CloseElement();
};
return form;
}
}
}
- 2 回答
- 0 关注
- 75 浏览
添加回答
举报