gpt4 book ai didi

jquery css 使用数组作为值

转载 作者:行者123 更新时间:2023-11-28 09:30:12 24 4
gpt4 key购买 nike

我正在创建一个函数,我需要从数组中传入值,我需要添加的值之一是 jquery css 数组的一系列值

基本上我需要做以下事情

myArray = new Array();
myArray[0] = ""{'float':'left','-webkit-border-top-left-radius':'20px','-webkit-border-bottom-left-radius':'20px','-webkit-border-top-right-radius':'0px','-webkit-border-bottom-right-radius':'20px'}";"
function(){
$("#myDiv").click(function(){
$(this).css(myArray[0]):
});
}

作为更大函数的一部分,这不是确切的代码,但是我失败的方面是将数组中的字符串传递给 .css 数组,如果我只包含值,我可以这样做在数组中,但这意味着我需要向我的数组添加我不想做的额外元素

任何帮助 - 将不胜感激

非常感谢!

所以对于上下文

好的,我的数组是 var card2Pos = new Array();
card2Pos[0]="475px";
card2Pos[1]="80px";
card2Pos[2]="1";
card2Pos[3]="500px";
card2Pos[4]="70px";
card2Pos[5]="90px";
card2Pos[6]="510px";
card2Pos[7]="9";<br/>
card2Pos[8]="{'float':'left','-webkit-border-top-left-radius':'20px','-webkit-border-bottom-left-radius':'20px','-webkit-border-top-right-radius':'0px','-webkit-border-bottom-right-radius':'20px'}";
card2Pos[9]="475px";
card2Pos[10]="80px";
card2Pos[11]="580px";
card2Pos[12]="60px";
card2Pos[13]="8";
card2Pos[14]="right";
card2Pos[15]="450px";
card2Pos[16]="90px";
card2Pos[17]="625px";
card2Pos[18]="60px";
card2Pos[19]="7";
card2Pos[20]="right";
card2Pos[21]="425px";
card2Pos[22]="100px";
card2Pos[23]="670px";
card2Pos[24]="60px";
card2Pos[25]="6";
card2Pos[26]="right";
card2Pos[27]="400px";
card2Pos[28]="110px";
card2Pos[29]="715px";
card2Pos[30]="60px";
card2Pos[31]="5";
card2Pos[32]="right";
card2Pos[33]="375px";
card2Pos[34]="120px";
card2Pos[35]="760px";
card2Pos[36]="60px";
card2Pos[37]="4";
card2Pos[38]="right";
card2Pos[39]="350px";
card2Pos[40]="130px";
card2Pos[41]="805px";
card2Pos[42]="60px";
card2Pos[43]="3";
card2Pos[44]="right";
card2Pos[45]="325px";
card2Pos[46]="140px";
card2Pos[47]="850px";
card2Pos[48]="60px";
card2Pos[49]="2";
card2Pos[50]="right";
被传递到以下函数` 功能优步(arg){ $card1.animate({ 高度:参数[0], 顶部:参数[1] },500).css({'z-index':card2Pos[2]});

    $card2.animate({
height:arg[3],
top:arg[4],
left:arg[5],
width:arg[6]
},500).css({'z-index':arg[7]});
$card2Nav.css(arg[8]);
$card3.animate({
height:arg[9],
top:arg[10],
left:arg[11],
width:arg[12]
},500).css({'z-index':arg[13]});
$card3Nav.css({'float':arg[14]});
$card4.animate({
height:arg[15],
top:arg[16],
left:arg[17],
width:arg[18]
},500).css({'z-index':arg[19]});
$card4Nav.css({'float':arg[20]});
$card5.animate({
height:arg[21],
top:arg[22],
left:arg[23],
width:arg[24]
},500).css({'z-index':arg[25]});
$card5Nav.css({'float':arg[26]});
$card6.animate({
height:arg[27],
top:arg[28],
left:arg[29],
width:arg[30]
},500).css({'z-index':arg[31]});
$card6Nav.css({'float':arg[32]});
$card7.animate({
height:arg[33],
top:arg[34],
left:arg[35],
width:arg[36]
},500).css({'z-index':arg[37]});
$card7Nav.css({'float':arg[38]});
$card8.animate({
height:arg[39],
top:arg[40],
left:arg[41],
width:arg[42]
},500).css({'z-index':arg[43]});
$card8Nav.css({'float':arg[44]});
$card9.animate({
height:arg[45],
top:arg[46],
left:arg[47],
width:arg[48]
},500).css({'z-index':arg[49]});
$card9Nav.css({'float':arg[50]});
}
`

最佳答案

您可以这样做,但不要将其存储为字符串 - 而是直接存储为对象,如下所示:

var myArray = [
{'float':'left','-webkit-border-top-left-radius':'20px','-webkit-border-bottom-left-radius':'20px','-webkit-border-top-right-radius':'0px','-webkit-border-bottom-right-radius':'20px'}
//more objects...
];
$(function(){
$("#myDiv").click(function(){
$(this).css(myArray[0]);
});
});

You can try it out here .

关于jquery css 使用数组作为值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4143627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com