问题在于克隆、拼接、删除、追加 jquery 函数
issue is with clone, splice, remove, append jquery function
HTML 中有多个图像。
<ul class="ice-navigator">
<li>
<a href="javascript:void(0);" class="thumb" id = "26">
<img src="images/123.png" alt="Title #0" width="75" height="75"/>
</a>
</li>
<li>
<a href="javascript:void(0);" class="thumb" id = "28">
<img src="images/456.png" alt="Title #0" width="75" height="75"/>
</a>
</li>
.
.
.
</ul>
我一次只想显示 5 张图像,所以我使用此代码"onload"来隐藏图像(如果图像超过 5 张)。
stPt = 0, elToShow = 5; //showing 5 elements
$ul = $('ul.ice-navigator');
$li = $('ul.ice-navigator li'); //get the list of li's
$copy_li = [];
copy_lgt = $li.length - elToShow;
for (var i = elToShow; i < $li.length; i++)
{
var tmp;
tmp = $li.eq(i);
$copy_li.push(tmp.clone());
tmp.remove();
}
为了显示上一个和下一个,我正在使用此代码。
$('.ice-next').click (function ()
{
$li = $('ul.ice-navigator li'); //get the list of li's
$copy_li.splice(copy_lgt, 0, $li.eq(0).clone() ); //move the 1st element clone to the last position in copy_li
$li.eq(0).remove(); //kill the 1st element in the UL
$ul.append($copy_li.shift()); //add to the last
});
$('.ice-previous').click (function ()
{
$li = $('ul.ice-navigator li'); //get the list of li's
$copy_li.splice(0, 0, $li.eq(elToShow-1).clone()); //move the 1st element clone to the last position in copy_li
$li.eq(elToShow-1).remove();//kill the 1st element in the UL
$ul.prepend($copy_li.pop());//add to the last
});
一切正常,除了这个:
有一个与拇指类关联的一键式事件。
jQuery(document).ready(function($) {
$(".thumb").click(function(){
alert ("Reaching here");
)};
)}:
这是在开始工作。 但是一旦我们使用
$('.ice-previous').click (function () or $('.ice-next').click (function ()
然后 $(".thumb").click(function(){ 不起作用。
我的意思是现在单击图像不会打印到达这里。
是什么导致了这个问题??
因为您要删除并重新附加 DOM 元素,所以您需要将事件委托给这些元素,如下所示:
$('.ice-navigator').on('click', '.thumb', function() {
alert('Reaching here');
});
更多信息: http://api.jquery.com/on/
相关文章:
- 如何在jquery中停止在更改时追加值
- JQuery.on(“keydown”)追加到页面时不工作
- jQuery[button.class]未检测到用按钮追加行
- 使用jQuery'生成输入字段;s追加
- 正在从JQuery追加Laravel Blade
- jQuery-根据值在输入字段后追加图像
- jQuery动态使用.append()添加输入,但发布表单不是追加数据
- 追加Jquery后的Binding Click事件不起作用
- 追加JQuery元素和Angular
- 如果数据不存在,则在表上追加jQuery
- 正在停止永不结束的追加.jQuery
- 问题在于克隆、拼接、删除、追加 jquery 函数
- 在 HTML 中动态追加 Jquery
- 追加 jquery 不起作用
- 无法追加 jquery
- 未追加 jQuery json 值
- 添加内容使用追加- Jquery
- 追加jQuery工作,但onclick不工作
- 不工作追加(jQuery)在代码中
- 不能向新包装的元素追加jquery元素