我有项目列表
<li><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));"></span></li>
<li><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));"></span></li>
<li><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));"></span></li>
<li><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));"></span></li>
<li><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));"></span></li>
和功能
function removeAnswer(that) {
console.log(that.parent().eq()); <-- I need know which element is clicked
that.parent().remove();
}
您知道我如何阅读eq
项中removeAnswer
项的内容吗?我无法在函数中传递第二个值,因为这是我的主脚本的一部分
我需要这个
console.log(that.parent().eq());
答案 0 :(得分:3)
通过这种方式,您可以检测到要移除的项目(我已将id
添加到li
元素以进行演示):
function removeAnswer(that) {
console.log(that.parent().attr('id'));
that.parent().remove();
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li id="one"><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));">1</span></li>
<li id="two"><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));">2</span></li>
<li id="three"><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));">3</span></li>
<li id="four"><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));">4</span></li>
<li id="five"><span class="glyphicon-remove glyphicon removeAnswerCount" onclick="removeAnswer($(this));">5</span></li>
答案 1 :(得分:2)
试试这个:
function removeAnswer(that) {
console.log($(".glyphicon-remove").index(that))
}
如果单击第4个答案,则会打印出3
,因为index()会在that
元素集合中返回从零开始的.glyphicon-remove
索引。
答案 2 :(得分:1)
您可以使用UPDATE _gtemp X
JOIN _gtemp Y
ON X.gt_spid = Y.gt_spid
AND X.gt_cov = Y.gt_cov
AND Y.gt_dna = 0
SET X.gt_dna = 1
WHERE Y.gt_gtid < X.gt_gtid
方法。
index