0

我需要在 sencha touch2 的面板中添加以下内容

<a href="https://twitter.com/share" class="twitter-share-button" data-text="Check out for more......" data-size="large" data-dnt="true">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

但它只是渲染

<div class="x-innerhtml " id="ext-element-156"><a href="https://twitter.com/share" class="twitter-share-button" data-text="Check out for more @z" data-size="large" data-dnt="true">Tweet</a>                   <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div> 

代替

<iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://platform.twitter.com/widgets/tweet_button.1352365724.html#_=1353049473087&amp;count=horizontal&amp;dnt=true&amp;id=twitter-widget-0&amp;lang=en&amp;original_referer=http%3A%2F%2Flocalhost%2Fmyapp%2Fchannel.html&amp;size=l&amp;text=Check%20out%20for%20more......&amp;url=http%3A%2F%2Flocalhost%2Fmyapp%2Fchannel.html" class="twitter-share-button twitter-count-horizontal" style="width: 136px; height: 28px; " title="Twitter Tweet Button" data-twttr-rendered="true"></iframe>
<script id="twitter-wjs" src="//platform.twitter.com/widgets.js"></script>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

我在 sencha 中使用以下代码

var tweetbtn = {
                xtype: 'panel',
                name: 'tweetbtn', 
                 id:"tweetbtn",
                width:100,height:100,
                html:'<a href="https://twitter.com/share" class="twitter-share-button" data-text="Check out for more......" data-size="large" data-dnt="true">Tweet</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>',

                } ;

我错过了什么?

4

1 回答 1

1

如上所示,您不能将标签添加到 html 属性。所有 javascript 真正做的是加载外部 Twitter javascript 文件并将其附加到您的元素。一旦面板被渲染以加载外部 Twitter 文件,您实际上应该只使用 loadScriptFile 函数 (http://docs.sencha.com/touch/2-1/#!/api/Ext.Loader-method-loadScriptFile)。

于 2012-12-05T05:42:27.700 回答