Javascript变量-设置为百分比
在我看来,“currentWidth”变量应该与父项宽度相同。但是在调试时,代码什么也不做。我认为这是因为,无论出于什么原因,两个宽度值都不相同 调用Javascript变量-设置为百分比,javascript,jquery,html,Javascript,Jquery,Html,在我看来,“currentWidth”变量应该与父项宽度相同。但是在调试时,代码什么也不做。我认为这是因为,无论出于什么原因,两个宽度值都不相同 调用.width()时缺少括号。更改: var currentWidth = $('.moreButton').parent().width(); $('.moreButton').click(function () { if ($(this)
.width()
时缺少括号。更改:
var currentWidth = $('.moreButton').parent().width();
$('.moreButton').click(function () {
if ($(this).parent().width == currentWidth) {
$(this).parent().animate({ width: '98%' }, 800);
$(this).text('Less');
}
调用
.width()
时缺少括号。更改:
var currentWidth = $('.moreButton').parent().width();
$('.moreButton').click(function () {
if ($(this).parent().width == currentWidth) {
$(this).parent().animate({ width: '98%' }, 800);
$(this).text('Less');
}
为什么你在问题的前面加上“更多”这个词?为什么你在问题的前面加上“更多”这个词
if ($(this).parent().width == currentWidth) {
// to
if ($(this).parent().width() == currentWidth) {