追加显示为未定义

时间:2019-05-05 14:28:28

标签: javascript jquery html append

在用户单击var Fake之后,我试图显示#fab_send的每个问题。但是没有显示var Fake的值,而是收到了undefined

请帮助我,如何解决此问题?

谢谢!

function insertMessage() {
		msg = $('#chatSend').val();
		if ($.trim(msg) == '') {
		  return false;
		}
		$('.chat_converse').append('<span class="chat_msg_item chat_msg_item_user"><p>' + msg + '</p></span>');
		$('#chatSend').val(null);
		setTimeout(function() {
		  fakeMessage();
		}, 1000 + (Math.random() * 20) * 100);
	  }
	  
	  $('#fab_send').click(function() {
		insertMessage();
	  });
	  
	  $(window).on('keydown', function(e) {
		if (e.which == 13) {
		  insertMessage();
		  return false;
		}
	  })
	  
	  var Fake = [
		'What is your Account Number?',
		'What is your full name?',
		'What is your date of birth?',
		'What is your e-mail address?',
		'What is your mobile number?',
		'Type your concern'
	  ]
	  
	  var i;
	  function fakeMessage() {
		if ($('#chatSend').val() != '') {
		  return false;
		}
		$('.chat_converse').append('<span class="chat_msg_item chat_msg_item_admin"><p></p></span>');
	  
		setTimeout(function() {
			$('.chat_converse').append('<span class="chat_msg_item chat_msg_item_admin"><p>' + Fake[i] + '</p></span>');
		  i++;
		}, 1000 + (Math.random() * 20) * 100);
	  
	  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="fabs">
		<div class="chat">
		  <div id="chat_converse" class="chat_conversion chat_converse">
		  </div>

		  <div class="fab_field">
        <a id="fab_send" class="fab"><i class="zmdi zmdi-mail-send"></i></a>
        <textarea id="chatSend" name="chat_message" placeholder="Send a message" class="chat_field chat_message"></textarea>
		  </div>
	</div>
		  <a id="prime" class="fab"><i class="prime zmdi zmdi-comment-outline"></i></a>
</div>

0 个答案:

没有答案