为什么在同一个类中触发click事件时不会触发更改事件?

时间:2015-06-12 06:32:16

标签: javascript jquery jquery-mobile

嗨我有代码,我正在使用jquery mobile创建一个移动应用程序。在我的代码中,我动态创建了页面并计算了员工的经验。由于id是在新创建的行上生成的,所以我正在服用class为触发事件的唯一类型。但是,如果在同一个类上触发点击事件,则不会触发该更改事件。' .Below是我的代码。请建议如何实现此目标?



<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <link href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://rawgithub.com/arschmitz/jquery-mobile-datepicker-wrapper/v0.1.1/jquery.mobile.datepicker.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script src="https://rawgithub.com/jquery/jquery-ui/1.10.4/ui/jquery.ui.datepicker.js"></script>
    <script id="mobile-datepicker" src="https://rawgithub.com/arschmitz/jquery-mobile-datepicker-wrapper/v0.1.1/jquery.mobile.datepicker.js"></script>
    <!-- Page Values and Script -->
    <script>
    $(document).ready(function() {
        $("input.add").live('click', function() {

            var length = 0;
            var table = $(this).closest('table').attr('id');

            if (table == 'Employee')
                var length = $('#Employee').find('tr').length;

            console.log(length);
            var $tr = $(this).closest('tr');
            var $clone = $tr.clone();
            $clone.find('input:text').val('');
                       
            var id2 = 'To' + length;
            console.log(id2);
            $clone.find(".to").parent().html(' <input class="to" id="' + id2 + '" name="To" type="text" value="" data-role="date" style="width:100%" />');

            $clone.find('input[data-role="date"]').date();
            console.log($clone);
            $tr.after($clone);
        });

        
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

尝试更改此代码

SELECT `IPAddress` AS CALL LocationFromIp('clientComp', `IPAddress`)
(
    SELECT `IPAddress`
    FROM `clientComp-data`.`tablename`
    WHERE @date > `Date`;
)
GROUP BY `IPAddress`

进入

 $('input.to').on('change', function(){...});

答案 1 :(得分:0)

我假设您使用的是jquery.1.7版本。因此,请尝试使用.live,如下所示:

$('input.to').live('change', function() {

或者如果动态添加的元素更好地使用$(document)来监听动态添加元素的事件

$(document).on('change','input.to', function() {
相关问题