小编ysf*_*qbl的帖子

如何在jQuery中克隆除数据之外的元素事件?

我试图用类".age-sex-details"克隆html div元素,并使用jquery clone函数绑定到下面显示的".age-sex-remove"和".age-sex-add"类的事件.我能够克隆div,上面提到的事件和使用.clone(true)函数输入到输入框中的数据,但我需要克隆div元素和提到的事件,但不是克隆在"count"中输入的数据和"年龄"输入字段.这可能吗?

守则简述

下面的jQuery代码包含文档就绪函数中的两个函数.你可以忽略第一个.第二个功能是我进行克隆的地方.我克隆下面的HTML中显示的div元素并将其插入其后.

iQuery代码

$(document).ready(function() {
        $(".age-sex-remove").click(function() {
            var index = $(".age-sex-details").length;
            if ( index > 1) {
                $(this).parent().remove();
                $($(".age-sex-add")[index - 2]).show();
            } else {
                console.log("only one set of age sex details, therefore clear values.")
            }
        });

        /**
         * Clone age-sex-details div including events and excluding data.
         * Hide the previous add new sex age details link.
         */
        $(".age-sex-add").click(function() {
            var index = $(".age-sex-details").length;
            console.log("Index = " +index);
            $($(".age-sex-details")[index - 1]).clone(true).insertAfter($(".age-sex-details")[index - 1]);
            $($(".age-sex-add")[index - 1]).hide();
        }); …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-clone

5
推荐指数
1
解决办法
2156
查看次数

为什么Twitter Bootstrap Carousel在第一次切换后会停止?

我正在尝试使用Twitter Bootstrap创建一个Carousel,但我得到了下面的错误,引用了第一次切换/滑动Carousel之后引导到bootstrap.js的第388行.

未捕获的TypeError:无法调用未定义的方法'slice'

我在Ubuntu上使用Chromium浏览器,版本32.0.1700.102 Ubuntu 12.10.

这是我正在使用的HTML.它几乎是来自http://getbootstrap.com/javascript/#carousel的副本

<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Corousel Example</title>

        <!-- Bootstrap -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>                
        <!-- Carousel START -->
        <!-- Indicators -->
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <ol …
Run Code Online (Sandbox Code Playgroud)

carousel twitter-bootstrap

2
推荐指数
1
解决办法
4967
查看次数