2 回答

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
function btn_click() {
//創(chuàng)建XMLHttpRequest對(duì)象
var xmlHttp = new XMLHttpRequest();
//獲取值
var username = document.getElementById("txt_username").value;
var age = document.getElementById("txt_age").value;
//配置XMLHttpRequest對(duì)象
xmlHttp.open("get", "action?user=" + <%=user%>
,true);
//設(shè)置回調(diào)函數(shù)
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
document.getElementById("result").innerHTML = xmlHttp.responseText;
}
}
//發(fā)送請(qǐng)求
xmlHttp.send(null);
}

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊
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 | //實(shí)體聲明 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( //實(shí)例化一個(gè)實(shí)體,添加到數(shù)組中 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('%', '')) ) }) //將對(duì)象序列化為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 + '時(shí)出現(xiàn)Ajax錯(cuò)誤:' + msg) }, success: function(responseText) { if (responseText == '1') { alert(temp + '成功!') LoadTable() } else alert(temp + '失??!操作數(shù)據(jù)庫(kù)時(shí)發(fā)生未知錯(cuò)誤') } }) } else if (!IsPageValidate()) alert('團(tuán)隊(duì)目標(biāo)信息填寫不完整') else if (IsOverINIS()) alert('團(tuán)隊(duì)自主目標(biāo)權(quán)重超限') else alert('團(tuán)隊(duì)目標(biāo)權(quán)重總和應(yīng)為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 關(guān)注
- 3891 瀏覽
添加回答
舉報(bào)