我有一個奇怪的問題,並且我的谷歌fu正在失敗我。我正在研究一個WordPress插件,並將設置頁面中的變量傳遞給jQuery腳本。除了在腳本中,它完全忽略了slideToggle()中速度的值,這一切都傳遞得很好。通過速度變量jQuery slideToggle()如果以毫秒爲單位被忽略
爲了記錄,我加載了一個jQuery腳本(jQuery UI - v1.11.2):核心和效果。
這裏是我的腳本:
jQuery(document).ready(function($) {
var $show_open_by_default = wp_settings.expanded;
var $showtext = wp_settings.show;
var $hidetext = wp_settings.hide;
var $speed = wp_settings.toggle_down;
var $easing = wp_settings.easing;
if($show_open_by_default != 1) { // if setting is unchecked...
$('.comment .children').hide(); // hide all children on load
}
$('.comment-list > li').each(function() {
if($(this).find('.children').length > 0) {
$(this).find('.children').before('<div class="replylink"><span class="show">'+$showtext+'</span></div>');
}
});
$('.replylink').hover(function() { // when hovering the replylink...
$(this).css('cursor','pointer'); // change the cursor...
}, function() {
$(this).css('cursor','auto');
}).click(function() { // and on click...
// change the text
$(this).text($(this).text() == $hidetext ? $showtext : $hidetext);
// animate the visibility of the children
var $nextDiv = $(this).next();
var $visibleSiblings = $nextDiv.siblings('div:visible');
if ($visibleSiblings.length == 0) {
$visibleSiblings.slideToggle($speed, $easing);
} else {
$nextDiv.slideToggle($speed, $easing);
}
});
});
這一切工作完全正常,除了在年底的slideToggle()調用。如果我放置警報($ speed);就在slideToggle()調用之前,它確實提醒了正確的設置。但是,slideToggle會忽略它並恢復爲默認速度。
有趣的是,如果我手動把一個值,它工作得很好。但隨着價值的傳遞,它忽略了它。我完全沉迷於此。我嘗試了所有我能想到的方法來使它注意這個數字,但是它只會在slideToggle()調用中對其進行硬編碼時纔會這樣做。如果它通過了,它將不會注意它。我錯過了什麼嗎?
任何幫助,將不勝感激。謝謝!
它將採用wp_settings.toggle_down的值; – 2014-12-04 13:41:41
你確定'$ speed'(和'wp_settings.toggle_down')是一個數字,而不是一個字符串? – 2014-12-04 13:42:32
是的。警報將顯示數字值,即使我將它直接放在對slideToggle()的調用之前。 和Bhojendra - 它*是*使用該值。我嘗試過使用該變量,並直接使用wp_settings.toggle_down獲得相同的結果。 – Shelly 2014-12-04 13:43:30