Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.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
Javascript 值和焦点()不处理动态创建的输入_Javascript_Php_Ajax - Fatal编程技术网

Javascript 值和焦点()不处理动态创建的输入

Javascript 值和焦点()不处理动态创建的输入,javascript,php,ajax,Javascript,Php,Ajax,我正在尝试创建一些东西,每30秒刷新一次所有用户的日期列表。 我使用AJAX在数据库中动态创建一个包含日期列表的表,问题是刷新会删除用户在刷新时写入的内容,因此我将保存用户在javascript全局变量中写入的内容,并调用刷新函数,然后用变量中的信息填充输入,并聚焦用户所关注的输入 问题是这些输入既没有被填充,也没有被聚焦 这是我的相关代码: var identificacionc = ""; var nombresc = ""; var apellidosc = ""; var telefon

我正在尝试创建一些东西,每30秒刷新一次所有用户的日期列表。 我使用AJAX在数据库中动态创建一个包含日期列表的表,问题是刷新会删除用户在刷新时写入的内容,因此我将保存用户在javascript全局变量中写入的内容,并调用刷新函数,然后用变量中的信息填充输入,并聚焦用户所关注的输入

问题是这些输入既没有被填充,也没有被聚焦

这是我的相关代码:

var identificacionc = "";
var nombresc = "";
var apellidosc = "";
var telefonoc = "";
var posicionc = 0;
var ladoc = 0;

//This is called on input onfocus to record the id
function recuerdo(posicion, lado)
{
    posicionc = posicion;
    ladoc = lado;
}

function actualizar()
{
    //This line is not relevant
    listaragenda();

    if (document.getElementById("datepicker").value != "")
    {
        //put the info in the global variables and it works even if they're dynamically created
        identificacionc = document.getElementById("txtidentificacion" + posicionc).value;
        nombresc = document.getElementById("txtnombres" + posicionc).value;
        apellidosc = document.getElementById("txtapellidos" + posicionc).value;
        telefonoc = document.getElementById("txttelefono" + posicionc).value;
        //Here is where I call the function to refresh dates
        listarcitas();    
    }
}

function listarcitas()
{
    var objAjax = crearObjeto();
    var fecha = document.getElementById("datepicker").value;
    objAjax.open("POST", "clases/listarcitas.php", true);
    objAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    objAjax.onreadystatechange = function() 
    {
        if (objAjax.readyState == 4 && objAjax.status == 200) 
        {
            document.getElementById("citaslistadas").innerHTML = objAjax.responseText;
            //Checks if any global variable is not empty to start to fill them with the info
            //nothing inside this If works
            //posicionc and ladoc have the correct values
            if (identificacionc != "")
            {
                document.getElementById("txtidentificacion" + posicionc).value = identificacionc;
                document.getElementById("txtnombres" + posicionc).value = nombresc;
                document.getElementById("txtapellidos" + posicionc).value = apellidosc;
                document.getElementById("txttelefono" + posicionc).value = telefonoc;

                if (ladoc == 1)
                {
                    document.getElementById("txtidentificacion" + posicionc).focus();
                }
                else if (ladoc == 2)
                {
                    document.getElementById("txtnombres" + posicionc).focus();
                }
                else if (ladoc == 3)
                {
                    document.getElementById("txtapellidos" + posicionc).focus();
                }
                else if (ladoc == 4)
                {
                    document.getElementById("txttelefono" + posicionc).focus();
                }
            }
        }
    }
    objAjax.send("fecha=" + fecha);
}

//the interval every 30s
window.setInterval("actualizar()", 30000);
从AJAX检索到的所有内容都可以正常工作。所有内容都会列出,即使在web浏览器控制台中,我也会对变量发出警报,设置值并聚焦动态创建的输入,所有内容都可以正常工作

但是为什么这在代码中不起作用呢


提前感谢

@Jose Manuel Abarca Rodríguez como dije,在firefox控制台中,使用了一个新的变量和一个新的变量,在listar citasactualizar()函数中存储变量页面并不刷新,我正在listarcitas()使用AJAX为了用dateswelp列表填充一个div,我自己解决了这个问题,如果listarcitas()内部没有检查nombresc、apellidosc和telefonoc,有时identificationc可能是空的。无论如何,谢谢你