【问题标题】:How to insert an ASP.NET databinder inside a javascript src string?如何在 javascript src 字符串中插入 ASP.NET 数据绑定器?
【发布时间】:2013-10-14 13:25:18
【问题描述】:

如何替换 javascript src 的选定字符串部分?

我希望将这个 插入到源字符串中。

原创

<script src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/youtube.xml&amp;up_channel=YourChannelName&amp;synd=open&amp;w=320&amp;h=390&amp;title=&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>

渴望

<script src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/youtube.xml&amp;up_channel=<%# DataBinder.Eval(Container.DataItem, "YouTubeChannel")%>&amp;synd=open&amp;w=320&amp;h=390&amp;title=&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>

工作示例

<a class="twitter-timeline"  href="https://twitter.com/<%# DataBinder.Eval(Container.DataItem, "TwitterUser")%>"  data-widget-id="<%# DataBinder.Eval(Container.DataItem, "TwitterID")%>">

当使用上述代码时,

【问题讨论】:

    标签: javascript asp.net sql-server string eval


    【解决方案1】:

    你的想法是对的。就像您在一串文本的中间输出一个数字一样。

    不过,您不需要转义引号,因为服务器会看到标签并输出值。 &lt;%# 基本上逃脱了它。

    <script src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/youtube.xml&amp;up_channel=<%# DataBinder.Eval(Container.DataItem, "YouTubeChannel")%>&amp;synd=open&amp;w=320&amp;h=390&amp;title=&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>
    

    应该这样做。当然,这确实需要包含在数据绑定控件中。

    【讨论】:

    • 谢谢 steven,我首先尝试了这个,因为这是我通常会这样做,但是
    • 它会导致脚本标签关闭。页面总失败。我在整个页面上都有锚标签,它们工作正常。请参阅上面的修改。
    猜你喜欢
    • 2010-09-05
    • 2021-12-05
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多