标签: conditional

为什么我的IE条件语句在样式标签内不起作用?

我正在尝试使用IE特定的条件语句来根据浏览器类型更改类设置.我觉得他们可以做到这一点,但我似乎无法让它发挥作用.

下面是一个简单的例子,如果浏览器是IE,文本应该是蓝色,否则文本应该保持红色.

"浏览器是IE"在机身上的声明工作正常,如果我打开firefox它不存在,Internet Explorer ..它是.

我究竟做错了什么?

<html>
<head>
<style type="text/css">
.class{color:red;}
<!--[if IE]>
.class{color:blue;}
<![endif]-->
</head>
</style>
<body>
<!--[if IE]>
This browser is IE
<![endif]-->
<p class="class">Color changing text based on browser</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html css conditional

1
推荐指数
1
解决办法
2535
查看次数

Java:如果只检查一次条件

我正在尝试使用以下代码在Java中创建一个简单的Android应用程序:

public class MainActivity extends Activity {

    //Declare variables
    boolean first = true;
    boolean secondorbefore = true;

        Button ClickMe = (Button) findViewById(R.id.clicker);

        ClickMe.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //Check to see if this is the first click
                if (first = true) {
                first = false;
                // DO STUFF FOR FIRST CLICK
                } else if ((secondorbefore = true) {
                    //so this is the second click?
                    secondorbefore = false;
                // DO STUFF FOR SECOND CLICK                
                    } else {
                    //OK …
Run Code Online (Sandbox Code Playgroud)

java conditional if-statement

1
推荐指数
1
解决办法
1753
查看次数

条件属性如何在幕后工作

我们有这个代码:

public static class MyCLass 
{
    [Conditional("Debugging")]  
    public static void MyMethod()
    {
         Console.WriteLine("Example method");
    }
}
.
.
.
//In debug mode: Executing Main method in debug mode
MyClass.MyMethod()
Run Code Online (Sandbox Code Playgroud)

我想知道的是条件属性如何改变MyMethod的行为,假设在.NET中Conditional属性定义为:

public class Conditional: Attribute
{
   .
   .
   public string Mode { get; set; )
   .
   .
   public Conditional(string Mode)
   {
       .
       .
       this.Mode = Mode;
       if (Mode == "Debugging")
       {
          #ifdef DEBUG
          //HOW THE CONDITIONAL CONSTRUCTOR COULD CHANGE THE BEHAVIOUR OF MyMethod
          #endif
       }
       .
       .
   }
}
Run Code Online (Sandbox Code Playgroud)

如何访问由我的属性(即来自MyAttribute类)修饰的资源(方法,成员,类......)?

.net c# debugging conditional custom-attributes

1
推荐指数
1
解决办法
107
查看次数

条件运算符?:类型评估

void method(Set<String> whiteListProviders){

        HashSet<String> hashedWhitelistedProviders;

        HashSet<String> fdsfh = (hashedWhitelistedProviders = (HashSet<String>) whitelistedProviders);

        HashSet<String> ghjk = (hashedWhitelistedProviders = new HashSet<String>(whitelistedProviders));

        HashSet<String> gh4jk = true ? fdsfh : ghjk; //compiles

        true?fdsfh:ghjk; //gives error "Type mismatch: cannot convert from HashSet<String> to boolean" 




}
Run Code Online (Sandbox Code Playgroud)

我读了http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.25, 但仍然无法理解为什么它在eclipse中给出了编译错误

java conditional

1
推荐指数
1
解决办法
67
查看次数

检查$ _GET是否可用且具有特定值?

我正在尝试检查$ _GET值是否可用且等于1,但错误是索引未定义.

<?php if ((isset($_GET['success'])) ||  ($_GET['success'] == 1)) { ?>
Do Something
<?php } ?>
Run Code Online (Sandbox Code Playgroud)

为什么这是个问题?我正在检查它是否存在然后是否等于一个,如果是,则做一些事情.

有没有更好的方法来实现这一目标?

php conditional

1
推荐指数
1
解决办法
113
查看次数

Ruby条件/案例表达

我对代码很新,我对Ruby条件有一个快速的问题,特别是Case表达式.我有一个方法,如果字符串长度为奇数,我想返回一个字符串"odd",如果字符串长度是偶数,我想返回"even".

我知道简单的东西,我可以使用if/else条件获得结果,但case表达式只返回'nil'.任何帮助将不胜感激.

def odd_or_even(string)
  case string
  when string.length.even? then "even"
  when string.length.odd? then "odd"
  end
end

odd_or_even("Ruby") # Wanting to return even rather than nil
odd_or_even("Rails") # Wanting to return odd rather than nil
Run Code Online (Sandbox Code Playgroud)

ruby conditional

1
推荐指数
1
解决办法
477
查看次数

C++ 11 std ::在运行时有条件?

我想做这样的事情:

void func(void *data, const int dtype)
{
    typedef typename std::conditional<dtype==0,float,double>::type DataType;

    funcT((DataType *)data);

    return;
}
Run Code Online (Sandbox Code Playgroud)

这不会编译,因为dtype需要在编译时知道.我试图避免使用switch语句,因为我正在使用8个数据类型,有许多函数,如上面的那些,通过ctypes从Python调用.

有没有像std :: conditional这样的方法可以在运行时完成,利用传入的dtype标识符?

c++ conditional std c++11

1
推荐指数
1
解决办法
417
查看次数

从列表生成多个条件语句

我有这样的清单

a = [1,0,6,9,6,0,6,0,1,4,0,7,5,0]
Run Code Online (Sandbox Code Playgroud)

我想创建一个像这样的条件语句:

if a[1,3,8,13] != 0:
    do something
Run Code Online (Sandbox Code Playgroud)

这段代码显然是错误的.它必须是这样的:

if a[1] != 0 and a[3] != 0 and a[8] != 0 and a[13] != 0:
    do something
Run Code Online (Sandbox Code Playgroud)

我想知道在我的情况下是否有更优雅的方法来使用lambda或loop编写多个条件语句.假设我的列表长度为100,我需要为列表的57列创建条件语句.我可能不想以这样的方式写出来......谢谢

python conditional if-statement python-3.x

1
推荐指数
1
解决办法
97
查看次数

Rewrite dynamic conditional statement in Javascript

I'm building a grid where a new item must fit in the next available spot. Items can be 3:2 or 2:3, the grid is 12 columns wide.

How can I rewrite this looped conditional statement to remove the hardcoded limit and accepts input of 3:2 or 2:3 (currently x:3,y:2)?

        const check = (
            !grid[rowY + 0][columnX + 0] &&  // @TODO: Hard coded limit
            !grid[rowY + 0][columnX + 1] &&  // @TODO: Hard coded limit
            !grid[rowY + 0][columnX + 2] …
Run Code Online (Sandbox Code Playgroud)

javascript conditional collision-detection

1
推荐指数
1
解决办法
51
查看次数

重构if块

在下面的代码中我有2个if块.
A,当对象为null时,第一个返回错误.
B,第二个将尝试发送对象,如果它失败则返回并出错.只有在不是A时才应该执行它,该对象不为null.

private bool SendToERP(Foo foo, out string error)
{
    error = "";
    var ticketIn = TicketFromFoo(foo, out string err);

    if(ticketIn == null)
    {
        error = err;
        return false;
    }

    if ( !GenericERP_TicketSubmit(ticketIn, out err))
    {
        error = err;
        return false;
    }

    return true;
}
Run Code Online (Sandbox Code Playgroud)

那些条件之后的动作是相同的,我想重构成一个独特的if块.

因为我不能扭曲我的头部状况,and我写了一个简单的真值表来帮助我.但它并没有帮助我变异.

c# refactoring conditional if-statement

1
推荐指数
1
解决办法
89
查看次数