52,797
社区成员
发帖
与我相关
我的任务
分享
<input type="text" id="txt1" value="123" />
<br />
<input type="text" id="txt2" />
<br />
<button id="a">
aaa</button>
<button id="aaa" onclick="aa()">
aaa</button>
$(document).ready(function () {
$("#a").click(function () {
var txt1 = $("#txt1").val();
var txt2 = $("#txt2").val();
if (txt1 == "") {
alert("aaaa");
return;
}
else {
alert("start")
return;
$.ajax({
type: "post",
url: "Default.aspx",
data: "Type=Doa",
success: function (data) {
alert(data);
}
});
alert("end")
}
if (txt2 == "") {
alert("txt2执行了");
return;
}
});
});
var req = null;
function aa() {
var txt1 = document.getElementById("txt1").value;
var txt2 = document.getElementById("txt2").value;
if (txt1 == "") {
alert("txt1 is null");
}
else {
alert("strat");
req = new XMLHttpRequest();
req.open("post", "Default.aspx?Type=Doa");
req.onreadystatechange = callback;
req.send(null);
alert("end");
}
if (txt2 == "") {
alert("txt2 is null")
}
}
function callback() {
if (req.readyState == 4) {
if (req.status == 200) {
alert(req.responseText);
return;
}
}
}
是的,但是还有就是jquery的方法返回的都是jquery对象
$(document).ready(function () {
$("#a").click(function () {
var txt1 = $("#txt1").val();
var txt2 = $("#txt2").val();
if (txt1 == "") {
alert("aaaa");
return;
}
else {
alert("start")
//return; 这个地方不能return吧,那不终止当前程序了
$.ajax({
type: "post",
url: "Default.aspx",
data: "Type=Doa",
success: function (data) {
alert(data);
}
});
alert("end")
}
if (txt2 == "") {
alert("txt2执行了");
return;
}
});
});