我需要创建一个变量,其中包含一些文字文本和来自输入的值。通过Ajax正确设置了输入。这是我的功能:
$(document).ready(function(){
$('#boat_id').blur(function(){
var regQuery = 'regNum='+$('#boat_id').val(),
classQuery ='class='+<?php echo $class ?>,
allQuery = classQuery+'&'+regQuery;
console.log('query= %s', allQuery);
$.getJSON('../ajax/registerBoatAjax.php',allQuery, function(data){
console.log(data);
$.each(data, function(theId, theVal){
var $el = $('#'+theId);
$el.val(theVal);
console.log(document.getElementById(theId));
});
});
$('#ownerAMYA').on('change', function(){
console.log("num="+$('$ownerAMYA').val());
var disp_amya =$('$ownerAMYA').val(),
disp_name =$('$ownerName').val(),
msg1 = 'Registered to <b>'+disp_name+'</b>, AMYA# <b>'+disp_amya+'</b>';
console.log(disp_name);
$('#content-msg1').html(msg1);
$('#content-msg1').css('visibility', 'visible');
});
});//end boat_id blur
});//end ready
第一个console.log正确显示对ajax文件的查询。 第二个(console.log(data)正确显示返回的JSON数据。 .each循环中的console.log显示了大多数值,但是缺少其中一个值(#ownerAMYA)。该值正确显示在页面上。 on('change'函数)中的console.log()未出现在控制台中。 msg1不会出现在控制台或输出中。 我做错了什么?