使用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
最满意答案
我想你想添加
| 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.
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);
You cannot set the baud rate as I was doing. You have to use the defined
B38400
;
baud = B38400;
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.
相关问答
更多-
串口挂起close()(Serial port hangs on close())[2022-02-11]
您的实现从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 ...
-
Elixir串口连接(Elixir serial port connection)[2022-01-25]
以下是针对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: ... -
验证串口连接(verify the serial port connection)[2022-02-14]
是的,如果您可以从您的端口传输数据并在另一台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 ... -
串口线程挂起(serial port threading hang)[2023-01-17]
当您在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 ...
-
C:read()挂起而没有从unix上的串口输入(C: read() hangs without getting input from serial port on unix)[2024-03-01]
看起来你的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( ... -
串口连接处理程序(Serial port connection handler)[2022-07-19]
在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 ...