问题1:我有三个变量。 className引用一个字符串。返回包含内容,链接包含
html字符串。我试图将内容分配给任何变量className引用。
var back = "test";
var className = "link1";
var link1 = '<div id="back" class="gohome"></div><div class="link3"></div><div class="link4"></div>';
因为以下代码似乎不适用于我
$(className) = className + back;
问题2:以下代码似乎并未更新prevClass包含的变量的CSS。
$('[id*="back"]').each(function(){
$('.' + prevClass).css({'left': '-123px'});
$('.' + prevClass).css({'top': '430px'});
$('.' + prevClass).css({'width': '123px'});
$('.' + prevClass).css({'height': '44px'});
<script type="text/javascript">
var back = "";
var prevClass = "start"
var className = "Broken";
start = '<div id="back" class="gohome"></div><div class="link1"></div><div class="link2"></div>';
gohome = '<div class="gohome"></div><div class="start"></div>';
link1 = '<div id="back" class="gohome"></div><div class="link3"></div><div class="link4"></div>';
link2 = '<div class="gohome"></div>';
link3 = '<div id="back" class="gohome"></div><div class="link5"></div><div class="link6"></div>';
link4 = '<div class="gohome"></div><div class="link7"></div><div class="link8"></div>';
link5 = '<div class="gohome"></div><div class="link2a"></div><div class="link10"></div>';
link6 = '<div class="gohome"></div><div class="link7"></div><div class="link11"></div>';
link6a = '<div class="gohome"></div><div class="link7"></div><div class="link11"></div>';
link7 = '<div class="gohome"></div><div class="link6a"></div><div class="link9"></div>';
link8 = '<div class="gohome"></div><div class="link2a"></div><div class="link10"></div>';
link9 = '<div class="gohome"></div><div class="link10a"></div>';
link10 = '<div class="gohome"></div><div class="link12"></div><div class="link13"></div>';
link10a = '<div class="gohome"></div><div class="link12"></div><div class="link13"></div>';
link11 = '<div class="gohome"></div><div class="link10a"></div>';
link12 = '<div class="gohome"></div><div class="link12"></div><div class="link13"></div>';
link13 = '<div class="gohome"></div><div class="link14"></div><div class="link15"></div>';
link14 = '<div class="gohome"></div>';
link15 = '<div class="gohome"></div><div class="link16"></div><div class="link17"></div>';
link16 = '<div class="gohome"></div>';
link17 = '<div class="gohome"></div><div class="link18"></div><div class="link19"></div>';
link18 = '<div class="gohome"></div>';
link19 = '<div class="gohome"></div><div class="link20"></div><div class="link21"></div>';
link20 = '<div class="gohome"></div>';
link21 = '<div class="gohome"></div>';
$(document).on('click', '.inter [class]', function () {
className = this.className;
$('[id*="back"]').each(function(){
$('.' + prevClass).css({'left': '123px'});
$('.' + prevClass).css({'top': '430px'});
$('.' + prevClass).css({'width': '123px'});
$('.' + prevClass).css({'height': '44px'});
});
back = '<div class="' + prevClass + '"></div>';
$('.' + className).html(back);
prevClass = className;
$('.inter').fadeTo(250, 0.25, function () {
$('.inter').html(window[className]);
$('.inter').css({'background-image': 'url("' + className + '.png")'});
$('.inter').fadeTo(250, 1.00);
});
});
</script>
最佳答案
对于问题一,您需要选择和更新一点点。由于classname是一个类名,因此您需要:$('.' + className)
(就像您已经找出问题2一样)
如果要更新内容(带有背面):$('.' + className).html(back);
对于问题2,目前尚不清楚您要做什么。
首先,#back
已经在DOM中了吗?这对您的link1变量无效。第二,prevClass应该是什么?
关于jquery - jQuery选择器和CSS错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16682775/