我正在尝试修改服务器端的 DIV 标签内容。
string url = "www.mypage.com";
string html = "<a href='http://www.facebook.com/sharer.php?u='"+url+" title='Submit to Facebook' target='blank'><img src='http://itprism.com/plugins/content/itpsocialbuttons/images/big/facebook.png' alt='Submit to Facebook'></a>" +
"<a href='http://twitter.com/share?text=Atlas Paving &url='" + url + " title='Submit to Twitter' target='blank'><img src='http://itprism.com/plugins/content/itpsocialbuttons/images/big/twitter.png' alt='Submit to Twitter'></a>";
divSocial.InnerHtml = html;
当我尝试导航到附加的 URL 时,我发现该 URL 生成不正确。附加的网址为空。这里有什么问题
最佳答案
您的结尾 ' 不正确。它应该在 url 之后关闭:
string html = "<a href='http://www.facebook.com/sharer.php?u=" + url + "' title= ...
避免这种难以发现的错误并使代码更易于阅读的一个好习惯是使用 string.Format
:
string html = string.Format("<a href='http://www.facebook.com/sharer.php?u={0}' title= ...", url);
关于c# - 将字符串附加到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15697422/