备忘录
本篇文章为小编的备忘录,对一些遇到的各种问题的解决方法进行简单的整理,方便自己查看,大家也能够參考。
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一起使用,不断监听文本框内容的变化
浙公网安备 33010602011771号