如何为隐藏的输入字段增加价值?在这种情况下,输入被创建为变量,然后在需要时插入到 DOM 中。编码:
<script>
var forma = $('form#mali_oglas'),
pomoc = $('div[role=pomoc]'),
div = $('.mali_oglas_pomoc'),
input = forma.find('input, textarea'),
code = forma.find('#code')
time_input = '<input type="hidden" name="time" />',
paid_input = '<input type="hidden" name="paid" value="1" />';
$('textarea').autosize();
input.on('click', function(e){
var name = $(':input:focus').attr("name");
pomoc.fadeOut('slow').promise().done( function(){
div.find("[data-pomoc='" + name + "']").fadeIn('slow');
});
});
code.on('focusout', function(){
var url = '<?php echo base_url() ?>global_info/gi_get_payment_code',
kod = $(this).val();
if ($('input[name=paid]').length != 1)
{
$.post(url, {code : kod}, function(data){
console.log(kod);
$('.mali_oglas_img_paid').slideDown('slow');
code.next('.mali_oglas_greska').remove();
code.after(time_input.val(data) + paid_input)
.css({'border' : '1px solid rgba(34,139,34,.5)'});
});
};
});
code.ajaxError(function() {
$(this).next('.mali_oglas_greska').remove();
$(this).after('<p class=mali_oglas_greska>Uneti kod je pogresan.</p>').css({'border' : '1px solid rgba(255,0,0,.5)'});
});
</script>