简体   繁体   English

输入字段未显示其设置值

[英]The input field is not displaying it set value

i have this as next and back button 我有这个作为下一个和后退按钮

This is the next button: 这是下一个按钮:

$(document).on('click', '#next_form', function () {
        emailAdress = $("#email").val();
        $(".column_1").flip({
        direction: 'rl',
        });
        $(".column_2").flip({
        direction: 'lr',
        });
});

back button: Then so i can revert the flip and insert the value again : 后退按钮:然后,我可以还原翻转并再次插入值:

$(document).on('click', '#back_form', function () {
    $(".column_1").revertFlip();
    $(".column_2").revertFlip();
    $("#email").val(emailAdress);
    console.log(emailAdress);
});

but the input field is not displaying the value when i console log it seems to be running perfect but it does display... any ideas why? 但是当我在控制台日志中输入字段未显示值时,它似乎运行完美,但确实显示了...为什么有任何想法?

You need to take var Fname, emailAdress, phoneNumber; 您需要输入var Fname, emailAdress, phoneNumber; out of the document.ready . document.ready

The basic problem was that when it flip javascript didn't register the motion so it didn't know the div elements had change, and had new content. 基本的问题是,当翻转javascript时,它没有注册动作,因此它不知道div元素已更改,并且具有新内容。 so when i flip them back the same thing happen. 因此,当我将它们翻转回去时,也会发生同样的事情。

the solution that i found was to listen for mutations on the DOM. 我发现的解决方案是侦听DOM上的变异。

   var observer = new MutationObserver(function(mutations, observer) {
        // fired when a mutation occurs
        console.log(mutations, observer);
        // ...
        $('#streetAddres').val(streetAddress);
        $("#numberPH").val(phoneNumber);
        $("#emailAd").val(emailAdress);
        $("#state").val(state);
        $("#name").val(Fname);
        $("#city").val(city);
        $("#zip").val(zip);

    });

    observer.observe(document, {
        subtree: true,
        attributes: true
        //...
    });

This example listens for DOM changes on document and its entire subtree, and it will fire on changes to element attributes as well as structural changes. 本示例侦听文档及其整个子树上的DOM更改,并将在元素属性更改和结构更改时触发。

i found a pretty useful example and more information about it on stack overflow here is the source: Is there a JavaScript/jQuery DOM change listener? 我找到了一个非常有用的示例,并且有关堆栈溢出的更多信息,这是源: 是否有JavaScript / jQuery DOM更改侦听器? you have to scroll down a little bit to see it. 您必须向下滚动一点才能看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM