我在这个页面上找到了一个很棒的 jQuery 代码,并在我的网站上使用了它。它工作得很好。带有 jQuery 的表单和实时预览。但是现在当我想更新数据库并再次打开表单时,它会正确地将文本放入表单字段中,但只有在我点击进出该字段后才会开始预览。如何强制我的函数在 mysqli 查询后直接启动预览?
$(document).ready(function() {
var commentNode = $('#lp-comment'),
contactNode = $('#lp-contact'),
contact = $('#contact'),
website = $('#website');
//comment...easy
$('#live-preview-form input, #live-preview-form textarea').bind('blur keyup',function() {
//comment
commentNode.text($('#comment').val());
commentNode.html($('#lp-comment').html().replace(/\n/g,'<br />'));
contactNode.text(contact.val() + ' says:');
});
});
$(document).ready(function() {
var commentNode = $('#lp-comment'),
contactNode = $('#lp-contact'),
contact = $('#contact'),
website = $('#website');
//comment...easy
$('#live-preview-form input, #live-preview-form textarea').bind('blur keyup',function() {
//comment
commentNode.text($('#comment').val());
commentNode.html($('#lp-comment').html().replace(/\n/g,'<br />'));
contactNode.text(contact.val() + ' says:');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="live-preview-form" class="lp-block field">
<input name="contact" class="input" placeholder="Kontaktperson" type="text" id="contact" value ="<?php echo $contact ?>" required />
</div>
<div id="live-preview-display" class="lp-block">
<div id="lp-contact"></div>
<div id="lp-comment"></div>
</div>