我正在努力隐藏推特按钮,一旦点击显示新内容,我认为我有它工作,但它仍然没有。我不确定为什么有人能指出我的错误会有所帮助。 感谢。
---- ---- UPDATE
当我添加此脚本时,它停止工作
<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
和
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
----更新结束----
以下是代码:
(function($) {
var win = null;
$.fn.tweetAction = function(options, callback) {
// Default parameters of the tweet popup:
options = $.extend({
url: window.location.href
}, options);
return this.click(function(e) {
if (win) {
// If a popup window is already shown,
// do nothing;
e.preventDefault();
return;
}
var width = 550,
height = 350,
top = (window.screen.height - height) / 2,
left = (window.screen.width - width) / 2;
var config = [
'scrollbars=yes', 'resizable=yes', 'toolbar=no', 'location=yes',
'width=' + width, 'height=' + height, 'left=' + left, 'top=' + top
].join(',');
// Opening a popup window pointing to the twitter intent API:
win = window.open('http://twitter.com/intent/tweet?' + $.param(options),
'TweetWindow', config);
// Checking whether the window is closed every 100 milliseconds.
(function checkWindow() {
try {
// Opera raises a security exception, so we
// need to put this code in a try/catch:
if (!win || win.closed) {
throw "Closed!";
} else {
setTimeout(checkWindow, 100);
}
} catch (e) {
// Executing the callback, passed
// as an argument to the plugin.
win = null;
callback();
}
})();
e.preventDefault();
});
};
})(jQuery);
$(document).ready(function() {
$('#tweetLink').tweetAction({
text: 'First tweet',
url: '#',
via: 'website'
}, function() {
$('hidden-text')
.show();
$(".hidden-text").removeClass("hidden-text");
});
});
$(document).ready(function() {
$("p").click(function() {
$(this).hide("slow");
});
});
&#13;
.hidden-text {
display: none;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Tweet to show content.
<a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button" id="tweetLink" data-show-count="false">Tweet to @your_twitter</a>
</p>
<p class="hidden-text">thank you for tweeting !</p>
&#13;
更新 优化了一些js
$(document).ready(function () {
$('#tweetLink').tweetAction({
text: 'First tweet',
url: '#',
via: 'website'
}, function () {
$('hidden-text')
.show("slow");
$(".hidden-text").removeClass("hidden-text");
$("#hide-me").hide("slow");
});
});
更新3
好的看着控制台我似乎得到了错误
Uncaught TypeError: $(...).tweetAction is not a function
我已经更新了我的Jquery CDN,当我点击Tweet到@your_twitter时,它现在不能在新窗口中打开但是在同一个窗口中更改了url。任何想法?
解决
我不得不删除一些CDN的
<link href="https://get.gridsetapp.com/35679/" rel="stylesheet"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<!--<script src="https://code.jquery.com/jquery-1.12.4.js"></script> -->
<!--<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>-->
<!--<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>-->
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<!--<script src="https://code.jquery.com/jquery-3.1.0.min.js" ></script>-->
答案 0 :(得分:1)
如果在添加这些脚本时它停止工作,请逐个添加脚本并检查js控制台是否有错误。这应该给你提示知道在哪里搜索错误。
同时检查这些库是否未加载两次。如果您已经加载了另一个jQuery库,例如,它将无法工作。
答案 1 :(得分:-1)
我在这里看到两种语法,但它们与您的问题无关。
<a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button"
id="tweetLink" data-show-count="false">Tweet to @your_twitter/a><a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button"
id="tweetLink" data-show-count="false">Tweet to @your_twitter </a> <!--Closing the tag-->
$('.hidden-text').show(); //class picker