JQuery(Javascript)CSS值和运算符(JQuery (Javascript) CSS Value & Operator)
我需要获取DIV-Container的CSS值Width。 然后我将这个宽度值除以245px。
伪代码:
var articles = "#showroom ul" css width / 245px
I need to get the CSS value Width of a DIV-Container. Then I will divide this width value through 245px.
Pseudo Code:
var articles = "#showroom ul" css width / 245px
原文:https://stackoverflow.com/questions/4097120
最满意答案
为了避免重新发明轮子和错误,您应该考虑使用像Apache Commons CLI这样的库,它将为您正确地解析您的命令。
public static void main(final String[] args) { Options options = new Options(); options.addOption( Option.builder("y") .required(true) .hasArg(true) .desc("The year") .longOpt("year") .build() ); options.addOption( Option.builder("m") .required(true) .desc("The months") .numberOfArgs(Option.UNLIMITED_VALUES) .longOpt("month") .build() ); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println( "Could not parse the command due to: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "java", options ); return; } String year = cmd.getOptionValue("y"); String[] months = cmd.getOptionValues("m"); // Rest of your code here }
然后,您可以在
--year
的情况下使用-y
或--year
提供参数,并在月份的情况下使用-m
或--month
。 如果出现解析错误,也会打印用法。
如果你想手动完成(假设你的年份首先跟着几个月),你的代码将是:
public static void main(final String[] args) { if (args.length < 2) throw new IllegalStateException("Not enough arguments"); String year = args[0]; String[] months = new String[args.length - 1]; System.arraycopy(args, 1, months, 0, months.length); ... }
但是我们应该添加更多的测试以确保参数的总量是正确的并且参数是有效的,这就是我建议使用库的原因。
To avoid reinventing the wheel and bugs, you should consider using a library like Apache Commons CLI which will parse your command properly for you.
public static void main(final String[] args) { Options options = new Options(); options.addOption( Option.builder("y") .required(true) .hasArg(true) .desc("The year") .longOpt("year") .build() ); options.addOption( Option.builder("m") .required(true) .desc("The months") .numberOfArgs(Option.UNLIMITED_VALUES) .longOpt("month") .build() ); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println( "Could not parse the command due to: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "java", options ); return; } String year = cmd.getOptionValue("y"); String[] months = cmd.getOptionValues("m"); // Rest of your code here }
You will then be able to provide your arguments using
-y
or--year
in case of the year and using-m
or--month
in case of the months. The usage will also be printed in case of a parsing error.
If you want to do it manually (assuming that you have the year first followed by the months), your code will then be:
public static void main(final String[] args) { if (args.length < 2) throw new IllegalStateException("Not enough arguments"); String year = args[0]; String[] months = new String[args.length - 1]; System.arraycopy(args, 1, months, 0, months.length); ... }
But we should add more tests to ensure that the total amount of arguments is correct and the arguments are valid which is the reason why I propose to use a library instead.
相关问答
更多-
在将项目作为.jar执行时无法找到bluecove jar(Unable to find bluecove jar while executing the project as a .jar)[2022-10-17]
这很简单 右键单击项目 - >构建路径 - >配置构建路径 - >订单和导出 如果没有勾选标记,则检查天蓝色库是否已标记 The problem was that I was trying to export it to a jar and then manually adding the main class in manifest.MD and the jars it was using. All I had to do was export it to an 'executable' jar and ... -
你可以从命令行使用2个工具来完成。 第一个是ASSOC,用于创建文件关联。 要验证是否为JAR类型定义了一个: >assoc .jar .jar=jarfile 如果没有找到,那么创建它: >assoc .jar=jarfile 下一步是定义关联。 这是通过FTYPE完成的。 要验证是否已经定义了,请键入 >ftype jarfile jarfile="C:\Program Files\Java\jre1.5.0_10\bin\javaw.exe" -jar "%1" %* 如果未找到或使用了错误的J ...
-
为了避免重新发明轮子和错误,您应该考虑使用像Apache Commons CLI这样的库,它将为您正确地解析您的命令。 public static void main(final String[] args) { Options options = new Options(); options.addOption( Option.builder("y") .required(true) .hasArg(true) ...
-
默认情况下,Java无法从jar中加载jar。 要做到这一点,你需要一个可以处理它的类加载器。 例如One-Jar 。 还有其他的选择(取决于你在罐子里放置罐子的方式,或者扁平罐子是一种选择),我建议对这个问题的答案 By default, Java cannot load jars from within jars. To accomplish this, you would need a classloader that can handle it. For example One-Jar. There ...
-
当您提供类File的构造函数的相对路径,如new File("config.properties") ,在场景后面,构建的绝对路径是 System.getProperty("user.dir") / config.properties user.dir实际上是User working directory ,也是您启动命令的目录。 When you provide a relative path to the constructor of the class File like new File("con ...
-
如何在命令promt创建jar文件时给出opencv的路径(How to give path of opencv during creating a jar file from command promt)[2023-04-04]
在创建jar文件或在命令提示符下编译时,无法将路径链接到动态库或.dll文件。 java中的OpenCV用作动态库,需要在运行时链接。 在IDE中,它有一个vm选项来为这些dll文件提供路径,或者它应该放在java.library.path中。 要链接这些.dll文件,首先编译项目,然后使用以下命令运行 java -Djava.library.path=c:\path_to_dll_file YourApp It is not possible to link path to dynamic librar ... -
吉姆,是的,你是对的。 实际上,我并没有完全遵循需要做的事情。 虽然指出哪个部分我错了,而不是标准的RTFM响应,你可能会更有帮助。 对于其他未来的人来说,这里是完整的/正确的/清理过的“make”批处理文件...... @echo off setlocal cls set HOME_DIR=D:\current\battle set CLASS_DIR=classes set SRC_DIR=src set CLASS_NAME=RemoveFiles set STUB=stub.bat cd /d ...
-
-jar开关旨在将jar作为独立程序启动。 如java手册页中所述: 使用-jar选项时,指定的JAR文件是所有用户类的源,并忽略其他类路径设置。 要提供类路径,请使用清单文件中的Class-Path条目。 深入阅读: Java™教程:将类添加到JAR文件的类路径 The -jar switch is intended to launch the jar as a self contained program. As stated in the java man page: When you use the ...
-
在jar文件中执行一个类(Executing a class in jar file)[2022-05-04]
我使用了命令: c:\installers> java -cp App1.jar com.RTC 它说: Exception in thread "main" java.lang.NoClassDefFoundError: org.openqa.selenium.WebDriver 该异常通常意味着找到.class文件,但它不包含正确的类。 检查你如何将它放入JAR。 它的目录和文件名必须与其包和类名相匹配。 它有时似乎也意味着没有找到二级课程。 通常,主JAR文件的清单的class-path条目中提到 ... -
可能你需要编写一个自定义类加载器(扩展ClassLoader),它允许你加载/卸载jar。 如果你可以卸载jar,你应该能够删除jar。 有用的链接http://docs.oracle.com/javase/tutorial/deployment/jar/jarclassloader.html 我可以动态卸载和重新加载(相同的其他版本)JAR吗? May be you would need to write a custom class loader(extending ClassLoader) which ...