2 回答

TA贡献2037条经验 获得超6个赞
function btn_click() {
//创建XMLHttpRequest对象
var xmlHttp = new XMLHttpRequest();
//获取值
var username = document.getElementById("txt_username").value;
var age = document.getElementById("txt_age").value;
//配置XMLHttpRequest对象
xmlHttp.open("get", "action?user=" + <%=user%>
,true);
//设置回调函数
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.getElementById("result").innerHTML = xmlHttp.responseText;
}
}
//发送请求
xmlHttp.send(null);
}

TA贡献1806条经验 获得超5个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | //实体声明 function target(code, content, isnt, temgix, temgix1, temgix2, temgix3, gruw) { this.code = code this.content = content this.isnt = isnt this.temgix = temgix this.temgix1 = temgix1 this.temgix2 = temgix2 this.temgix3 = temgix3 this.gruw = gruw } function AddTarget(type) { if (IsPageValidate() && IsPerHan() && !IsOverINIS()) { var array = new Array() $('.outSTr,.innerSTr').each(function() { var inputs = $(this).find('input') array.push( //实例化一个实体,添加到数组中 new target(inputs.eq(0).attr('id').split('_')[0], inputs.eq(0).val(), inputs.eq(1).prop("checked") ? 1 : 0, $('#' + inputs.eq(0).attr('id').split('_')[0]).val(), inputs.eq(3).val(), inputs.eq(4).val(), inputs.eq(5).val(), inputs.eq(6).val().replace('%', '')) ) }) //将对象序列化为json,以便传输 var JsonStr = JSON.stringify(array); var temp = type == 1 ? '保存' : '提交' $.ajax({ type:'POST', url: _rootUrl + "WebService/HAddPerformanceTarget.ashx", data: { "type": type, "id": $('[id$=ddlPara]').val(), "Json": JsonStr }, error: function(xhr, msg) { alert(temp + '时出现Ajax错误:' + msg) }, success: function(responseText) { if (responseText == '1') { alert(temp + '成功!') LoadTable() } else alert(temp + '失败!操作数据库时发生未知错误') } }) } else if (!IsPageValidate()) alert('团队目标信息填写不完整') else if (IsOverINIS()) alert('团队自主目标权重超限') else alert('团队目标权重总和应为100%') } function IsPageValidate() { var inputs = $('.perTable input:text') var result = true inputs.each(function() { if ($.trim($(this).val()) == '') { result = false } }) if (!result) return false for (var i = 1; i <= 10; i++) { var thisradioC = $('input:radio[name="c' + i + '_int"]:checked').val() var thisradioD = $('input:radio[name="d' + i + '_int"]:checked').val() if ($('input:radio[name="c' + i + '_int"]').length > 0) if (thisradioC == undefined) return false if ($('input:radio[name="d' + i + '_int"]').length > 0) if (thisradioD == undefined) return false } return true } function IsOverINIS() { var $outAndInner = $('.outSTr,.innerSTr') var sum = 0 $outAndInner.each(function() { if ($(this).find('input:radio:checked').val() == '是') sum += parseInt($(this).find('input:last').val()) }) return sum>parseInt($('#inis').text()) } function IsPerHan() { var inputs = $('.perTable input:text') var sum = 0 for (var i = 4; i < inputs.length; i = i + 5) sum += parseInt(inputs.eq(i).val().replace('%', '')) return sum == 100 } |
- 2 回答
- 0 关注
- 3864 浏览
添加回答
举报