Jquery mobile jQuery移动克隆

Jquery mobile jQuery移动克隆,jquery-mobile,Jquery Mobile,我试图让jquerymobile像在jsfiddle上一样克隆div 头 $(document).bind('mobileinit',function(){ $.mobile.page.prototype.options.addBackBtn=true; $.mobile.page.prototype.options.backBtnText=“Back”; $.mobile.page.prototype.options.backBtnIcon=“arrow-l”; $.mobile.selec

我试图让jquerymobile像在jsfiddle上一样克隆div


$(document).bind('mobileinit',function(){
$.mobile.page.prototype.options.addBackBtn=true;
$.mobile.page.prototype.options.backBtnText=“Back”;
$.mobile.page.prototype.options.backBtnIcon=“arrow-l”;
$.mobile.selectmenu.prototype.options.nativeMenu=false;
$.mobile.page.prototype.options.keepNative=“.native”;
$.mobile.keepnactive=“.native”;
})
HTML


分析物:
挑选
总氮
TP,NO2+3
TP、NO2+3、NH3+4
溶解正磷酸盐
TR金属,硬度
溶解铝(FF)
TR金属(汞)
TSS
TSS/TDS
溶解金属(FF)
TOC
阴离子、溴、氟
阳离子、硬度
0.45u过滤
场重复
保存
挑选
HNO₃;
H₂;所以₄;
H₃;采购订单₄;
盐酸
没有一个
冷却的
挑选
冰
冻结的
没有一个
剧本

 <script>
    $(document).ready(function() {
      (function ($) {
    var Template = $('#Template');
    var count = 0;
    var nextId = 0;

    Template.find('.removeNew').on('click', function (e) {
        e.preventDefault();
        $(this).closest('.template').remove();
        count--;
    });

    function cloneTemplate(removable) {
        var clone = Template.clone(true, true);
        clone.attr('id', clone.attr('id') + nextId);

        clone.find('label[for]').each(function( index ) {
            var elem = $(this);
            elem.attr('for', elem.attr('for') + nextId);
        });

        clone.find('select, input').each(function( index ) {
            var elem = $(this);
            elem.attr('id', elem.attr('id') + nextId);
            elem.attr('name', elem.attr('name') + nextId);
        });

        if (!removable) {
            clone.find('.removeNew').remove();
        }

        clone.insertBefore("#addNew").removeClass('hide');
        count++;
        nextId++;
    }

    // Create First Analyte and delete the remove button.
    cloneTemplate(false);

    $('a.showNew').on('click', function (e) {
        e.preventDefault();
        cloneTemplate(true);
        return false;
    });
   })(jQuery)
    });
    </script> 

$(文档).ready(函数(){
(函数($){
变量模板=$(“#模板”);
var计数=0;
var-nextId=0;
Template.find('.removeNew')。on('click',函数(e){
e、 预防默认值();
$(this).closest('.template').remove();
计数--;
});
功能克隆模板(可移动){
var clone=Template.clone(true,true);
clone.attr('id',clone.attr('id')+nextId);
clone.find('label[for]')。每个(函数(索引){
var elem=$(本);
要素属性('for',要素属性('for')+nextId);
});
clone.find('select,input')。每个(函数(索引){
var elem=$(本);
要素属性('id',要素属性('id')+nextId);
元素属性('name',元素属性('name')+nextId);
});
如果(!可移动){
clone.find('.removeNew').remove();
}
clone.insertBefore(“#addNew”).removeClass('hide');
计数++;
nextId++;
}
//创建第一个分析物并删除删除按钮。
克隆模板(假);
$('a.showNew')。在('click',函数(e){
e、 预防默认值();
克隆模板(真);
返回false;
});
})(jQuery)
});
我在jQuery方面得到了很多帮助,但无论我做什么,它都无法在jQuery mobile中工作。要么是它反向克隆(第一项变为最后一项,所有字段都已填充),要么是新div上的新字段不允许我填充它们(当前版本)


我没有创建提琴,因为我尝试过的所有东西都在提琴中工作,只是在手机中没有。我从你提供的链接中查看了你的页面来源,我不确定你到底想实现什么,因为你有一个复杂的表单。但是,请将我在下面修改过的代码放在页面的
标记之前,并删除您目前拥有的其他脚本部分。请确保在需要撤消我提供的这些更改之前备份JQM应用程序

我还注意到一些$(document).ready(function(){在您的页面中,不需要这些函数,因此请将它们删除。只需简单地单击函数即可。您可以将所有这些函数合并到一个
////
下。函数的放置位置很重要,因为有些函数需要位于
中,有些位于
中,有些位于
标记之后

<script>

    var Template = $('#Template');
    var count = 0;
    var nextId = 0;

    Template.find('.removeNew').on('click', function (e) {
        e.preventDefault();
        $(this).closest('.template').remove();
        count--;
    });

    function cloneTemplate(removable) {
        var clone = Template.clone(true, true);
        clone.attr('id', clone.attr('id') + nextId);

        clone.find('label[for]').each(function( index ) {
            var elem = $(this);
            elem.attr('for', elem.attr('for') + nextId);
        });

        clone.find('select, input').each(function( index ) {
            var elem = $(this);
            elem.attr('id', elem.attr('id') + nextId);
            elem.attr('name', elem.attr('name') + nextId);
        });

        if (!removable) {
            clone.find('.removeNew').remove();
        }

        clone.insertBefore("#addNew").removeClass('hide');
        count++;
        nextId++;
    }

    // Create First Analyte and delete the remove button.
    cloneTemplate(false);

    $('a.showNew').on('click', function (e) {
        e.preventDefault();
        cloneTemplate(true);
        return false;
    });

    </script> 

变量模板=$(“#模板”);
var计数=0;
var-nextId=0;
Template.find('.removeNew')。on('click',函数(e){
e、 预防默认值();
$(this).closest('.template').remove();
计数--;
});
功能克隆模板(可移动){
var clone=Template.clone(true,true);
clone.attr('id',clone.attr('id')+nextId);
clone.find('label[for]')。每个(函数(索引){
var elem=$(本);
要素属性('for',要素属性('for')+nextId);
});
clone.find('select,input')。每个(函数(索引){
var elem=$(本);
要素属性('id',要素属性('id')+nextId);
元素属性('name',元素属性('name')+nextId);
});
如果(!可移动){
clone.find('.removeNew').remove();
}
clone.insertBefore(“#addNew”).removeClass('hide');
计数++;
nextId++;
}
//创建第一个分析物并删除删除按钮。
克隆模板(假);
$('a.showNew')。在('click',函数(e){
e、 预防默认值();
克隆模板(真);
返回false;
});

用pageinit事件替换ready。像这样?$(文档)。在('pageinit',function(){(function($){}var Template=$('#Template');是的,您不需要
(function($){}
。现在它做了不同的奇怪事情——我就是不明白。我现在可以再改变初始div了,但仍然以同样的方式响应。克隆的div不允许我打开selects。我试图通过单击Add Analyte来克隆第一部分。我可以使用所有的选择,我单击Add Analyte并获得克隆,但我不能e使用选择项
 <script>
    $(document).ready(function() {
      (function ($) {
    var Template = $('#Template');
    var count = 0;
    var nextId = 0;

    Template.find('.removeNew').on('click', function (e) {
        e.preventDefault();
        $(this).closest('.template').remove();
        count--;
    });

    function cloneTemplate(removable) {
        var clone = Template.clone(true, true);
        clone.attr('id', clone.attr('id') + nextId);

        clone.find('label[for]').each(function( index ) {
            var elem = $(this);
            elem.attr('for', elem.attr('for') + nextId);
        });

        clone.find('select, input').each(function( index ) {
            var elem = $(this);
            elem.attr('id', elem.attr('id') + nextId);
            elem.attr('name', elem.attr('name') + nextId);
        });

        if (!removable) {
            clone.find('.removeNew').remove();
        }

        clone.insertBefore("#addNew").removeClass('hide');
        count++;
        nextId++;
    }

    // Create First Analyte and delete the remove button.
    cloneTemplate(false);

    $('a.showNew').on('click', function (e) {
        e.preventDefault();
        cloneTemplate(true);
        return false;
    });
   })(jQuery)
    });
    </script> 
<script>

    var Template = $('#Template');
    var count = 0;
    var nextId = 0;

    Template.find('.removeNew').on('click', function (e) {
        e.preventDefault();
        $(this).closest('.template').remove();
        count--;
    });

    function cloneTemplate(removable) {
        var clone = Template.clone(true, true);
        clone.attr('id', clone.attr('id') + nextId);

        clone.find('label[for]').each(function( index ) {
            var elem = $(this);
            elem.attr('for', elem.attr('for') + nextId);
        });

        clone.find('select, input').each(function( index ) {
            var elem = $(this);
            elem.attr('id', elem.attr('id') + nextId);
            elem.attr('name', elem.attr('name') + nextId);
        });

        if (!removable) {
            clone.find('.removeNew').remove();
        }

        clone.insertBefore("#addNew").removeClass('hide');
        count++;
        nextId++;
    }

    // Create First Analyte and delete the remove button.
    cloneTemplate(false);

    $('a.showNew').on('click', function (e) {
        e.preventDefault();
        cloneTemplate(true);
        return false;
    });

    </script>