小编nik*_*nik的帖子

如何使<div>标签表现为<a>标签?

这是网页代码:

<html>
    <head>
        <link rel="stylesheet" type="text/css" href="css.css"  >
    </head>
    <body>
        <script>
            function func() {   
                // do some checks
                window.location = "http://google.com";
            }    
        </script>

        <a href="http://google.com">link</a>
        <br><br>
        <a href="http://google.com"><div class="button">button 1</div></a>
        <br>
        <div class="button" onclick="func()">button 2</div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是css文件:

a, a:hover, a:visited, a:active {
    color: inherit;
    text-decoration: none;
}

.button {
    width: 100px;    
    display: block;
    background-color: #cccccc; 
    cursor: pointer;
    text-align: center;
    border: 1px solid #666666;
    padding: 3px;
}
Run Code Online (Sandbox Code Playgroud)

<a>网页开头有简单的链接 - 当用户点击某个网站加载的链接时.

然后有一个div用作按钮,它也包装在<a>标签中,当用户点击该div时它也会导致同一个站点.

然后有另一个div用作按钮,但它不包装在<a>标签中,当用户点击该div时,会调用一些javascript函数,并在一些检查后加载相同的站点.

这就是问题.当用户将鼠标悬停在链接上或首先div在用户浏览器底部显示URL( …

html css

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

以下代码的复杂性

我被赋予了以下任务:

鉴于 - 2列表.第一个列表的大小是N1,第二个列表的大小是N2.每个列表都没有相同的元素.编写一个代码,使用第一个和第二个列表中的元素创建一个新列表.此列表也不应具有相同的元素.还要估算代码的复杂性.

我写了以下代码:

public class Lists {    
    static ArrayList<Integer> getNewList(ArrayList<Integer> list1, 
                                         ArrayList<Integer> list2) {
        ArrayList<Integer> tmp = new ArrayList<>();
        for (Integer i : list1) {
            tmp.add(i);
        }
        for (Integer i : list2) {
            if (!list1.contains(i)) 
                tmp.add(i);
        }
        return tmp;
    }

    public static void main(String[] args) { 
        Integer[] arr1 = {1, 2, 3, 14, 15, 16};        
        Integer[] arr2 = {3, 6, 7, 8, 14};
        ArrayList<Integer> list1 = new ArrayList<>(Arrays.asList(arr1));
        ArrayList<Integer> list2 = new ArrayList<>(Arrays.asList(arr2));
        for (Integer i : getNewList(list1, …
Run Code Online (Sandbox Code Playgroud)

java algorithm performance

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

Java - 如何知道当前是否正在运行特定方法

我有 2 个 Web 应用程序:Application1 和 Application2——都是 REST 应用程序。

Application1 有时会调用 Application2 中的方法。

这是非常重要的部分 - 只有这个方法的一个实例应该同时运行。因此,在从 Application1 调用 Application2 中的方法之前,会调用额外的请求来测试方法是否在当前时刻运行。

现在我以这种方式实现它(它不是实际代码 - 这只是为了大致显示实际代码的作用):

static Boolean ifRunning = false;

static void methodWrapper() throws Exception {

    try {
        ifRunning = true;
        method();
    } finally {
        ifRunning = false;
    }
}

static void method() {
    // do something
}

static Boolean monitorMethod() {
    return ifRunning;
} 
Run Code Online (Sandbox Code Playgroud)

在这段代码中:

  • "method" - 该方法只有一个实例应该同时运行
  • "monitorMethod" - 此方法用于监控

这不是最好的解决方案:“methodWrapper”中的“finally”可能不会执行(在某些情况下 - 例如 System.exit(0)),因此在某些时候“ifRunning”可以在方法结束时保持为真。结果从那一刻开始,Application1 认为该方法一直在运行。

那么对于我的目标有更好的解决方案吗?

java

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

标签 统计

java ×2

algorithm ×1

css ×1

html ×1

performance ×1