您好,登錄后才能下訂單哦!
ajax格式,(key:value,)value值用單引號括起來
$.ajax({
type:, //'post','get'
url:, //action的路徑
data:, //傳到后臺的參數,多個參數的連接符為'&'
success:function(msg){}//對返回的JSP頁面或結果進行處理
});
1)jsp:
<td style="width:155px;">
<input type="text" name="sn" id="sn" onkeyup="getsn()" value ="${sn}" autocomplete="off"/>
</td>
<td style="width:155px;">
<%--<div id="div_sn" style="position:absolute;left :150;top:10;z-index:0;width:155px;"> </div> --%>
<div id="div_sn" style="width:155px;"> </div>
</td>
2)Javascript:
data的值表示把頁面的值傳到后臺(/GetSN.action),多個參數的連接符為'&'
執行成功后把結果放到一個JSP頁面(ajaxSN.jsp),通過 success:function(msg),放到ID為'div_sn'
function getsn(){
document.getElementById("div_sn").style.display="block";
var sn = $('#sn').val();
var product=$('#product').val();
if(sn.length>5){
$.ajax({
type:'post',
url:'<%=request.getContextPath()%>/GetSN.action',
timeout:2000,
data:'sn='+$('#sn').val() +'&product='+$('#product').val(),
success:function(msg){
$("#div_sn").html(msg);
}
});
}
}
3)ajaxSN.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style type="text/css">
.DivSelect
{
position: relative;
background-color: transparent;
width: 135px;
overflow: hidden; /*隱藏了小三角,因為寬度為110px,而select寬度為130px*/
border-width:0px;
border-top-style: none;
border-right-style: none;
border-left-style: none;
border-bottom-style: none;
}
/*設置Select樣式*/
.SelectList
{
position: relative;
background-color: transparent;
border-width: 0px;
border-top-style: none;
border-right-style: none;
border-left-style: none;
border-bottom-style: none;
width:155px;
display:block;
overflow:hidden;
}
</style>
</head>
<body>
<div class="DivSelect">
<select class="SelectList" name="select_sn" id="select_sn" onchange="select_getSN();">
<option value="${sn}" >${sn}</option>
<s:iterator value="snList" id='char' status='st'>
<option value="${char}"> ${char}</option>
</s:iterator>
</select>
</div>
</body>
</html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。