首页 \ 问答 \ 使用jQuery动态创建div(Dynamically creating divs with jQuery)

使用jQuery动态创建div(Dynamically creating divs with jQuery)

有人可以赐教我为什么下面的代码不起作用?

   for(var i=0; i<4; i++) {

        var ref = i+1;

        $("#test").append("<div id='t" + ref + "'>In t" + ref + "</div>");
    }

我的目的是在'test'div内创建子div。 但是当我用'$(“#test> div”)。size()'检查时,它返回'0'。 我还尝试了其他一些替代方案,包括在'基于可变数字的jQuery动态生成Div'中提到的那个,但这也返回相同的结果'0'。

我正在使用“jquery-1.6.4.js”(也尝试使用“jquery-1.6.2.js”)。

希望有人可以指出我做错了什么。


Can someone kindly enlighten me why the following code of mine does not work?

   for(var i=0; i<4; i++) {

        var ref = i+1;

        $("#test").append("<div id='t" + ref + "'>In t" + ref + "</div>");
    }

My intention is to create child divs inside 'test' div. But when I check with '$("#test > div").size()', it returns '0'. I've also tried some other alternative including the one mentioned in 'Dynamically Generating Divs with jQuery based on variable number' post, but this also return the same result '0'.

I am using "jquery-1.6.4.js" (also tried with "jquery-1.6.2.js").

Hope someone can point out what am I doing wrong.


原文:https://stackoverflow.com/questions/7962997
更新时间:2023-10-07 13:10

最满意答案

我想你想添加| O_SYNC | O_SYNC到打开标志来坚持同步I / O。 我怀疑这是造成问题,但。

不过,我认为你想忽略中断信号,这是一个NUL角色,就像你得到的那样:

tty_settings.c_iflag &= ~IGNBRK;         // ignore break signal

另外,您要确保输入处理完全关闭,以便接收退格,^ C,^ \等不会触发任何反应:

tty_settings.c_lflag = 0;                // no signaling chars, no echo,
                                         // no canonical processing

它看起来像你已经在使用我的set_blocking()函数 ,所以应该没问题。


Here's what I ended up doing. I figured this out by basically copying and pasting parts from cutecom's source code.

  1. When opening...

    int fd, n;
    fd = open (device_path, O_RDONLY | O_NOCTTY | O_NDELAY);
    
    ... error check fd ...
    
    n = fcntl(ail_info->ail_serial_fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, n & ~O_NDELAY);
    
  2. You cannot set the baud rate as I was doing. You have to use the defined B38400;

    baud = B38400;

  3. Then, I added wallyk's answer.

    tty_settings.c_lflag = 0;

Edit: As per sawdust comment, I found a better way to set this to raw input.

tty_options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

And it works.

相关问答

更多
  • 您的实现从tx_empty()返回0 ,这意味着“ 不为空 ”。 来自kernel.org/doc/Documentation/serial/driver : tx_empty(port) 此函数测试'port'描述的端口的发送器fifo和shifter是否为空。 如果为空,则此函数应返回TIOCSER_TEMT ,否则返回0.如果端口不支持此操作,则应返回TIOCSER_TEMT 。 Your implementation returns 0 from tx_empty() which means "no ...
  • 您可以修改while循环,如下所示: figure s = serial('COM11'); fopen(s) while(s.BytesAvailable > 0) if (strcmp(comsStatus, 'open') == 1) tline(i) = str2num(fgetl(s)); i = i+1 plot(tline(1:i-1)) drawnow end ...
  • 以下是针对Serial.start_link的elixir_serial中的文档: 启动串口。 调用此函数的进程将以{:elixir_serial, pid, data}的形式接收消息。 因此,您实际上并不需要GenServer来处理响应。 只需在代码中添加以下格式的接收块: receive do {:elixir_serial, serial_pid, data} -> IO.puts "Received data" Serial.send_data(serial_pid, "ACK: ...
  • 是的,如果您可以从您的端口传输数据并在另一台PC上接收数据,那么您没有理由不能在微控制器上接收它 - 显然您也需要在微控制器端使用正确的硬件和软件。 。 Yes, if you can transmit data from your port and receive it on another PC, then there's no reason why you shouldn't be able to receive it on your microcontroller - obviously you'l ...
  • 当您在StopReading()中关闭端口时,它将在_serialPort.Read(...)中导致异常。 不确定哪一个确切但它不是TimeOut。 你当前的代码让你逃脱,那就是你的线程和你的应用程序被杀死的时候。 因此,在ReadPort()中的while循环周围添加一个catch(Exceptiopn ex) )。 When you close the Port in StopReading() it will cause an Exception in _serialPort.Read(...). N ...
  • 我想你想添加| O_SYNC | O_SYNC到打开标志来坚持同步I / O。 我怀疑这是造成问题,但。 不过,我认为你想忽略中断信号,这是一个NUL角色,就像你得到的那样: tty_settings.c_iflag &= ~IGNBRK; // ignore break signal 另外,您要确保输入处理完全关闭,以便接收退格,^ C,^ \等不会触发任何反应: tty_settings.c_lflag = 0; // no signaling chars ...
  • 问题是我在if指令中调用了serial.open() ,导致每次执行只打开一次。 为了工作,我在配置端口后立即放置了serial.open()方法。 正确和完整的代码(对我有用)是这样的: /*Create the serial port and configure it*/ QSerialPort serial; serial.setPortName("COM39"); serial.setBaudRate(QSerialPort::Baud9600); serial.setDataBits(QSeria ...
  • 看起来你的printf只是在它到达换行符之前没有被刷新。 这就是为什么你得到输出的第一部分,而不是第二部分。 您可以在printf之后添加fflush(stdout)以立即查看输出。 Looks like your printf is just not being flushed until it hits a newline. That's why you get the first part of the output, but not the second. You could add fflush( ...
  • 在Task.Run()运行long running work时long running work Task.Run() 。 当您执行Task.Run() ,默认情况下它在由默认thread Task.Run()管理的thread上执行。 如果使用thread.sleep(1)执行无限循环,则实际上是阻塞了池中的一个线程。 假设您运行的是8个逻辑核心,那么最终只有7个可用,因为您永远阻止其中一个线程。 如需更多阅读,请了解为什么这很糟糕。 这是关于干扰线程池的一个很好的读数。 更好的实施方式是: Task.F ...
  • 等待不能解决你从调用Close()得到的死锁,你需要修复核心问题。 它几乎总是由DataReceived事件处理程序中的代码引起的。 我们看不到它,但一个非常常见的错误是使用Control.Invoke()或Dispatcher.Invoke()。 在事件处理程序返回之前,串行端口无法关闭。 但它无法返回,因为它停留在Invoke()调用中。 由于你的UI线程很忙,它无法完成,它停留在Close()调用中。 或者正在等待BytesToRead达到0,这是您正在追求的解决方案。 也无法工作,您的DataRec ...

相关文章

更多

最新问答

更多
  • 您如何使用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)