备忘录

本篇文章为小编的备忘录,对一些遇到的各种问题的解决方法进行简单的整理,方便自己查看,大家也可以参考。


1.ajax的同步异步问题

var msg='';
	$.ajax({
		url: 'messageAction.do?reqCode=order',
        type: 'post',
        data:{
             },
	    dataType: "json",      
	    success:
	        function (data) {
	    	msg=data.msg;
	    	alert(msg);
	    }
	});   
	alert(msg);
对这个ajax请求,第一个alert可以正确的弹出请求到的数据,但第二个alert却弹出空值,这是因为这个ajax请求为异步的,当执行第二个ajax时ajax请求的数据还未返回,所以无法正确弹出。可以改成下面的形式(同步的)

$.ajax({
		url: 'messageAction.do?reqCode=order',
        type: 'post',
        data:{
             },
	    dataType: "json",   
	    async:false,     <span style="font-family: Arial, Helvetica, sans-serif;">//同步</span>
	    success:
	        function (data) {
	    	msg=data.msg;
	    	alert(msg);
	    }
	});   

2.input的光标问题

<input type="text" id="" value="123" size="15" onChange="alert('内容改变')">
<input type="button" id="" value="计算" onClick=alert('这是我的事件')>
<input type="text" id="" value="我获得焦点了" size="15" onFocus="alert('我获得焦点了')">
<input type="text" id="" value="我失去焦点了" size="15" onBlur="alert('我失去焦点了')">
<input type="text" id="" value="鼠标悬停事件"size="15"onMouseOver="alert('鼠标悬停事件')">
<input type="text" id="" value="鼠标移出事件" size="15"onMouseOut="alert('鼠标移出事件')">
<input type="text" id="" value="鼠标移动事件"size="15"onMouseMove="alert('鼠标移动事件')">
<input type="button" id="" value="点击" onMouseDown=alert('鼠标按下事件')>
<input type="button" id="" value="点击" onMouseUp=alert('鼠标弹起事件')>
<input type="submit" id="" value="提交" onSubmit=alert('表单提交')>

onpropertychange和oninput一起使用,不断监听文本框内容的变化



版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/dingxiaoyue/p/4931780.html