c#
  • asp.net
  • url
  • 2013-03-29 117 views 1 likes 
    1

    我试图修改服务器端的DIV标记内容。将字符串附加到URL

    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没有正确生成。附加的网址为空。请告诉我错在这里

    enter image description here

    回答

    6

    您的交易“是不正确的。它应该在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); 
    
    1

    可以尝试:

    而不是
    string html = "<a href='http://www.facebook.com/sharer.php?u="+url+"' title='Submit to Facebook' target='blank'> 
    

    <a href='http://www.facebook.com/sharer.php?u='"+url+" title='Submit to Facebook' target='blank'> 
    

    我想你过早地关闭了你的href属性。

    相关问题