小编Kab*_*uky的帖子

JavaScript jQuery绑定

我正在使用jQuery创建一个锚并将其与JavaScript函数绑定如下:

  $(document).ready
    (
        function()
        {
                var test = function(arg)
                           {
                              alert(arg);
                           }
                var anotherTest = function(arg)
                                  {
                                         do something;
                                   }
                $('#id').click
                (
                    var content = "Hello world";
                    var anchor = "<a href='javascript:void(0);' onclick='test(\"" + content + "\")' >test</a>";

                     $('#DivToBind').prepend(anchor);
                );
            }
    );
Run Code Online (Sandbox Code Playgroud)

问题是:无论内容的价值是什么,测试功能总是警告"a".如果我将onclick函数测试更改为anotherTest,则没有任何反应,但错误控制台中出现"anotherTest未定义"

编辑

为了更好地识别我的问题,我总结了我的实际代码如下

   $(document).ready
    (
        function()
        {

                  var deleteComment = function (comment)
                    {
                          commentInfo       = comment.split('_');
                         var postid         = commentInfo[0];
                        var enum        = commentInfo[1];
                        var parentid    = commentInfo[2];
                        var user        = commentInfo[3];
                        var author      = commentInfo[4];
                        var date …
Run Code Online (Sandbox Code Playgroud)

javascript jquery binding

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

C#多线程行为

我写了一个简单的多线程片段,让自己习惯了这个概念.

public void testThread(int arg1, ConsoleColor color)
    {
        for (int i = 0; i < 1000; i++)
        {
            Console.ForegroundColor = color;
            Console.WriteLine("Thread " + color.ToString() + " : " + i);
            Console.ResetColor();
            Thread.Sleep(arg1);
        }
    }

Thread t1 = new Thread(() => program.testThread(1000, ConsoleColor.Blue));
Thread t2 = new Thread(() => program.testThread(1000, ConsoleColor.Red));
t1.Start();
t2.Start();
t1.Join();
t2.Join();
Run Code Online (Sandbox Code Playgroud)

我在输出控制台窗口中看到的是

在此输入图像描述

我只是不明白为什么有时用红色装饰的线可能会变成白色或浅灰色(无论如何).你能帮助启发这个想法吗?

提前致谢.

c# multithreading

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

null比较,前缀增量,属性,C#中struct的Length属性

我在C#中有一些问题

  1. null比较之间有什么区别null == value和value == null(value是任何类型的变量:int,string,float,...)

  2. 我听说在某些情况下使用前缀增量++ i而不是i ++将增强程序性能.为什么会这样?

  3. 我有一个代码段如下:

        private int _number;            
        public int Number
        {
           get { return _number}
           set { _number = value}
        }
    
        public double Test
        {
           get
           {
              if (null == Number)
                  return 1.1;
              else
                  return 2.2;
           }
        }
    
    Run Code Online (Sandbox Code Playgroud)

问题是为什么我们在这里使用null == Number但不是null == _number或Number == null或_number == null

4. if I have a struct as follow:

    public struct Vector
    {
        public double X;
        public double Y;

        public Vector(double x, double y)
        {
            X = x; …
Run Code Online (Sandbox Code Playgroud)

c# comparison null properties

0
推荐指数
2
解决办法
378
查看次数