我使用以下代码作为我想要使用的手风琴类型,但它允许选择和打开多个面板。我希望它强制关闭其他面板,只打开所选的面板:
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select").change(function(){
$(this).find("option:selected").each(function(){
var optionValue = $(this).attr("value");
if(optionValue){
$(".box").not("." + optionValue).hide();
$("." + optionValue).show();
} else{
$(".box").hide();
}
});
}).change();
});
</script>
我完全生锈了。谢谢你的帮助。
答案 0 :(得分:0)
在函数首次运行时关闭它们,然后只打开当前目标。
答案 1 :(得分:0)
如果选项的值始终与选项类匹配,则代码应该有效。当您执行$('.box').not('option[value="' + optionValue + '"]').hide();
$('option[value="' + optionValue + '"]').show();
时,您正在搜索与class属性不匹配的所有内容,但- (NSString *) qCustomDescription
{
static int depth = 0;
NSMutableString *resultString = [NSMutableString stringWithFormat: @"<%@: %p>", NSStringFromClass([self class]), self];
uint32_t ivarCount;
Ivar *ivars = class_copyIvarList([self class], &ivarCount);
if( ivars )
{
++depth;
[resultString appendString: @"\n"];
for( int tabs = depth; --tabs > 0; )
[resultString appendString: @"\t"];
[resultString appendString: @"{"];
for( uint32_t i = 0; i < ivarCount; ++i )
{
Ivar ivar = ivars[i];
const char* type = ivar_getTypeEncoding(ivar);
const char* ivarName = ivar_getName( ivar );
NSString* valueDescription = @"";
NSString* name = [NSString stringWithCString: ivarName encoding: NSASCIIStringEncoding];
switch( type[0] )
{
case '@':
{
id v = object_getIvar(self, ivar);
if( v )
{
if( [self respondsToSelector: @selector(qDescriptionForValue:)] )
valueDescription = [self performSelector: @selector(qDescriptionForValue:) withObject: v];
else
valueDescription = [v description];
}
break;
}
case 'c':
{
char v = ((char (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%c", v];
break;
}
case 'i':
{
int v = ((int (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%i", v];
break;
}
case 's':
{
short v = ((short (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%d", v];
break;
}
case 'l':
{
long v = ((long (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%ld", v];
break;
}
case 'q':
{
long long v = ((long long (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%lld", v];
break;
}
case 'C':
{
unsigned char v = ((unsigned char (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%uc", v];
break;
}
case 'I':
{
unsigned int v = ((unsigned int (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%u", v];
break;
}
case 'S':
{
unsigned short v = ((unsigned short (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%u", v];
break;
}
case 'L':
{
unsigned long v = ((unsigned long (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%lu", v];
break;
}
case 'Q':
{
unsigned long long v = ((unsigned long long (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%llu", v];
break;
}
case 'f':
{
float v = ((float (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%f", v];
break;
}
case 'd':
{
double v = ((double (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%f", v];
break;
}
case 'B':
{
BOOL v = ((BOOL (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%@", v ? @"YES" : @"NO"];
break;
}
case '*':
{
char *v = ((char* (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"%s", v];
break;
}
case '#':
{
id v = object_getIvar(self, ivar);
valueDescription = [NSString stringWithFormat: @"Class: %s", object_getClassName(v)];
break;
}
case ':':
{
SEL v = ((SEL (*)(id, Ivar))object_getIvar)(self, ivar);
valueDescription = [NSString stringWithFormat: @"Selector: %s", sel_getName(v)];
break;
}
case '[':
case '{':
case '(':
case 'b':
case '^':
{
valueDescription = [NSString stringWithFormat: @"%s", type];
break;
}
default:
valueDescription = [NSString stringWithFormat: @"UNKNOWN TYPE: %s", type];
break;
}
[resultString appendString: @"\n"];
for( int tabs = depth; --tabs >= 0; )
[resultString appendString: @"\t"];
[resultString appendFormat: @"%@: %@", name, valueDescription];
}
[resultString appendString: @"\n"];
for( int tabs = depth; --tabs > 0; )
[resultString appendString: @"\t"];
[resultString appendString: @"}"];
--depth;
free(ivars);
}
return resultString;
}
来自value属性。我假设类/值属性不匹配(不能在没有HTML的情况下告诉),所以它不会隐藏任何内容。
对于选择器来说,这样的东西应该可以工作而不需要匹配类:
for (int r = 0; r < rows; r++) {
for (int c = 0; c < columns; c++) {
int distanceToEdgeOfRow = Math.abs(rows - (r - rows)); //this finds the number of steps to the nearest row end
int distanceToEdgeOfColumn = Math.abs(columns - (c - columns)); //this find the number of steps to the nearest column end
int shortestPath = Math.min(distanceToEdgeOfColumn, distanceToEdgeOfRow); //is it shorter to take the closest row exit or column exit?
//the shortestPath is still off by one, so we need to add 1 to shortestPath to see what should be printed on this tile
matrix[r][c] = shortestPath + 1;
}
}