如何使用jQuery生成动态ID?(How to generate dynamic id using jQuery?)
我想将渐进ID添加到无序HTML列表中的一系列元素。 我使用jQuery
.each()
方法来获取列表中的每个<li>
,并在每个<li>
添加一个<span>
<li>
。 然后我添加了以每个()的索引作为编号的ID属性。$('#menu li ul li').each(function(i, e){ $(this).append('<span class="arr"></span>'); $(".arr").attr("id", "id_" + i); });
但是我得到了所有元素的
id_3
。 为什么? 我做错了什么?谢谢你的帮助!
I want to add progressive id to a series of elements on an unordered HTML list. I used the jQuery
.each()
method to get each<li>
of the List and append a<span>
inside each<li>
. Then I added the ID attribute with index of each() as number.$('#menu li ul li').each(function(i, e){ $(this).append('<span class="arr"></span>'); $(".arr").attr("id", "id_" + i); });
But I get
id_3
for all elements. Why? What did I do wrong?Thanks for any help!
原文:https://stackoverflow.com/questions/22913512
最满意答案
从MySQL参考手册https://dev.mysql.com/doc/refman/5.7/en/concurrent-inserts.html
如果存在多个INSERT语句,则它们将与SELECT语句同时排队并执行。
由于MySQL不会同时插入记录,因此可以使用单个线程并避免死锁。
如果你必须有多线程的INSERT,可以考虑使用try-catch块。 如果发生死锁,请尝试再次插入。 如果最终陷入无限循环,请放置一个计数器,并且不要尝试永久插入。 请尝试仅插入预定义的时间(计数器)。
From MySQL Reference Manual https://dev.mysql.com/doc/refman/5.7/en/concurrent-inserts.html
If there are multiple INSERT statements, they are queued and performed in sequence, concurrently with the SELECT statements.
Since MySQL does not insert records simultaneously, you can use a single thread and avoid deadlocks.
If you must have multi threads that INSERT, consider using try-catch blocks. If deadlock occurs, try to insert again. If you end up in an infinite loop, put a counter and don't try to insert forever. Instead try to insert only a predefined time(counter) by you.
相关问答
更多-
试试这个 mysql_query("INSERT INTO `Servers` (`ip`, `desc`, `type`, `title`) VALUES('".$ip."', '".$desc."', '".$type."', '".$title."')") or die(mysql_error()); desc是MySql的保留关键字,因此不能在没有反引号的情况下使用它。 Try this mysql_query("INSERT INTO `Servers` (`ip`, `desc`, `typ ...
-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您使用addBatch和executeBatch ,这很好,但您还需要将连接上的自动提交设置为false,以便实现更快的执行时间。 一些事情: Connection conn = mysqlconn.getConnection(); conn.setAutoCommit(false); // here PreparedStatement ps = null; String query = "insert into table (column) values (?)"; System.out.print ...
-
InnoDB表批量插入(InnoDB Table Bulk Insert)[2023-05-28]
我的第一直觉是要求你调整你的缓冲区变量..但正如你所说,你不能改变很多服务器配置参数,这是另一种选择...... 进行计算并将输出转储到csv中。 您可以使用'SELECT ... INTO OUTFILE'命令。 然后,您将连接到目标InnoDB,并执行'set autocommit = 0',然后执行'load data local infile'将此CSV加载回目标表。 最后将autocommit变回1。 我可以提出许多其他选项(例如正确的分区模式,主键顺序插入等),但我需要知道数据库的结构,传入的数 ... -
MySQL中多线程和批量插入表中的死锁[复制](Deadlock in multithread and bulk inserting into a table in MySQL [duplicate])[2023-04-20]
从MySQL参考手册https://dev.mysql.com/doc/refman/5.7/en/concurrent-inserts.html 如果存在多个INSERT语句,则它们将与SELECT语句同时排队并执行。 由于MySQL不会同时插入记录,因此可以使用单个线程并避免死锁。 如果你必须有多线程的INSERT,可以考虑使用try-catch块。 如果发生死锁,请尝试再次插入。 如果最终陷入无限循环,请放置一个计数器,并且不要尝试永久插入。 请尝试仅插入预定义的时间(计数器)。 From MySQL ... -
好吧,我想出了如何在Node 6.x中使用第一个查询来完成它。 我必须通过的价值如下: [[[1, 1, 1, 1, Buffer.from('
', 'hex')],[2, 2, 2, 2, Buffer.from(' ', 'hex')]]] Okay so I figured out how to do it in Node 6.x using the first query. The values I had to pass were as so: [[[1, 1, 1, 1, ... -
desc是一个用于order by和whatnot的关键字 通过添加反引号魔术引用来逃避desc : insert into subreddits_subreddit(name, `desc`, admin_id) values('firstSubreddit', 'This is a test.', 1) desc is a keyword for use with order by and whatnot Escape desc by putting backtick magic quotes: ...
-
每个命名的占位符都必须是唯一的! $stmt = $dbPDO->prepare("INSERT INTO group_members(g_id, em_id) VALUES(:g_id,:em_id) ON DUPLICATE KEY UPDATE g_id = :g_id2, em_id = :em_id2"); $email=null; //just bind once, that the logic behind 'bind()' $stmt->bindParam(':g_id', $gid , ...
-
我直接从这里解除了这个问题: 重复密钥更新 - 多列 如果它有效,你应该给他/她一个碰撞。 INSERT INTO my_table (name, email) VALUES ('john', 'abc@d.co'), ('foo','def@g.org') ON DUPLICATE KEY UPDATE name=VALUES(name) email=VALUES(email) I lifted this directly from here: On Duplicate Key U ...