Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从<;输入>;id=和value=的动态值,并将它们作为变量在javascript中使用_Javascript_Php_Jquery - Fatal编程技术网

从<;输入>;id=和value=的动态值,并将它们作为变量在javascript中使用

从<;输入>;id=和value=的动态值,并将它们作为变量在javascript中使用,javascript,php,jquery,Javascript,Php,Jquery,我使用clockpicker()作为在php页面上输入时间的工具,该页面包含许多类似但唯一的字段 它的工作原理如下: <?php while // ...extracting data from mysql // and we have got a lot of "cards" (Their quantity is not constant and there can be from 30 to 100 cards), each one of them has unique card_n

我使用clockpicker()作为在php页面上输入时间的工具,该页面包含许多类似但唯一的字段

它的工作原理如下:

<?php while // ...extracting data from mysql

// and we have got a lot of "cards" (Their quantity is not constant and there can be from 30 to 100 cards), each one of them has unique card_numuber and card_time
echo <div id='card'> ;
echo <div id='$row['card_numuber']'> $row['card_numuber']</div> ;
echo <div class='input-group clockpicker-with-callbacks'><input id='$row['card_numuber']' type='text' class='form-control' value=".$row['card_time']."></div>;
echo </div> ;
?>

遗憾的是,看看源代码,该插件没有通过
完成后的
回调任何有用的东西。因此,为了了解与之相关的输入,我们必须以更详细的方式连接:

// Normally, you'd avoid using `each` like this, but sadly this plugin calls
// its callbacks with NO context information
$('.clockpicker-with-callbacks').each(function() {
    var input = $(this).find("input")[0];
    $(this).clockpicker({
        donetext: 'Done',
        afterDone: function() {
            var card_time = input.value; // The current value of the input
            var card_numuber = input.id; // The input's ID

            console.log(card_numuber, card_time);
            $.post( "2_settime.php", { 
                card_numuber: card_numuber, card_time: card_time
            });
        }
    });
});

遗憾的是,从源代码看,该插件没有通过
afterDone
回调任何有用的东西。因此,为了了解与之相关的输入,我们必须以更详细的方式连接:

// Normally, you'd avoid using `each` like this, but sadly this plugin calls
// its callbacks with NO context information
$('.clockpicker-with-callbacks').each(function() {
    var input = $(this).find("input")[0];
    $(this).clockpicker({
        donetext: 'Done',
        afterDone: function() {
            var card_time = input.value; // The current value of the input
            var card_numuber = input.id; // The input's ID

            console.log(card_numuber, card_time);
            $.post( "2_settime.php", { 
                card_numuber: card_numuber, card_time: card_time
            });
        }
    });
});

注意:您的代码在多个元素(一个div和一个input)上放置了相同的ID。那是无效的。解决这个问题的一种方法是给它们两个前缀。不,$row['card\u number']和$row['card\u time']都是唯一和动态的。哦,你是说id=$行['card\u number']和中的是相同的$row['card\u number']…您有
注意:您的代码在多个元素(一个div和一个input)上放置了相同的ID。那是无效的。解决这个问题的一种方法是给它们两个前缀。不,$row['card\u number']和$row['card\u time']都是唯一和动态的。哦,你是说id=$第['card\u number']行和第['card\u number']行是同一个$row…您有
,还有
谢谢。但我无法让它工作<代码>变量$this=$(this)是解决我问题的关键。我得到了它。但是我在控制台中有这个
类型错误:e.nodeName未定义
@PhilippNesterov:抱歉,没有注意到您正在调用插件方法。我看到你已经链接了文档,让我们快速浏览一下……我已经尝试过<代码> var CARTHARTIMEST= THE.Valk;var card_number=this.id在控制台中,我有
未定义的未定义的
@PhilippNesterov:哇,文档没有告诉我们任何有用的信息,并且查看源代码,它没有向回调传递任何有用的信息。Blech,不是一个设计良好的插件。我已经更新了答案来解释这一点。@PhilippNesterov:…现在我已经修复了它,我没有注意到您的类位于
div
上,而不是输入。您应该看到
var-input=$(this.find(“input”)[0]在上面的代码中;如果没有,请点击刷新。谢谢。但我无法让它工作<代码>变量$this=$(this)是解决我问题的关键。我得到了它。但是我在控制台中有这个
类型错误:e.nodeName未定义
@PhilippNesterov:抱歉,没有注意到您正在调用插件方法。我看到你已经链接了文档,让我们快速浏览一下……我已经尝试过<代码> var CARTHARTIMEST= THE.Valk;var card_number=this.id在控制台中,我有
未定义的未定义的
@PhilippNesterov:哇,文档没有告诉我们任何有用的信息,并且查看源代码,它没有向回调传递任何有用的信息。Blech,不是一个设计良好的插件。我已经更新了答案来解释这一点。@PhilippNesterov:…现在我已经修复了它,我没有注意到您的类位于
div
上,而不是输入。您应该看到
var-input=$(this.find(“input”)[0]在上面的代码中;如果没有,点击刷新。