首页 \ 问答 \ JQuery(Javascript)CSS值和运算符(JQuery (Javascript) CSS Value & Operator)

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
更新时间:2022-02-07 21:02

最满意答案

为了避免重新发明轮子和错误,您应该考虑使用像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.

相关问答

更多
  • 这很简单 右键单击项目 - >构建路径 - >配置构建路径 - >订单和导出 如果没有勾选标记,则检查天蓝色库是否已标记 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 ...
  • 在创建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 ...
  • 我使用了命令: 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)