小编Jeo*_*Nam的帖子

为什么比较运算的结果值与数学上相同的公式不同?

我在比较向量和简单常量的大小时遇到​​问题-1

我相信这两者在逻辑上是相同的:

  • (index >= (arr.size() - 1))
  • ((index + 1) >= arr.size())

但是,第一个返回1not 0。两者比较有什么区别?

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int index = -1;
  vector<char> arr(6);
  cout << (index >= (arr.size() - 1)) << endl;
  cout << ((index + 1) >= arr.size()) << endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ gcc

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

ready() 工作,on('ready') 不工作,为什么?

我试图在我的代码中使用 'on' 但失败了。我试过的代码是这样的:

<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script type="text/javascript">
    function clickHandler(e) {
      alert('Click!');
    }
    $(document).on('ready', function() {
      $('#click_me').on('click', clickHandler);
    })
  </script>
</head>

<body>
  <input id="click_me" type="button" value="click me" />
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

虽然我可以用下面的代码替换这段代码。我仍然想知道为什么我的第一个事件代码on不起作用。

<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script type="text/javascript">
    function clickHandler(e) {
      alert('Click!');
    }
    $(document).ready(function() {
      $('#click_me').click(clickHandler);
    })
  </script>
</head>

<body>
  <input id="click_me" type="button" value="click me" />
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

jquery jquery-events

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

标签 统计

c++ ×1

gcc ×1

jquery ×1

jquery-events ×1