風(fēng)信建站應(yīng)用實(shí)際項(xiàng)目的開發(fā)過(guò)程,項(xiàng)目需求為通過(guò)文字鏈接模擬表單提交數(shù)據(jù),在處理表單提交數(shù)據(jù)的時(shí)候,我們會(huì)有兩種方式,第一種是直接在文字鏈接后面接傳遞的參數(shù),第二種是使用JQuery模擬一個(gè)表單提交請(qǐng)求,下面的代碼片段主要是說(shuō)明通過(guò)隱藏Form表單提交數(shù)據(jù)查詢結(jié)果的實(shí)現(xiàn),示例代碼如下:
HTML代碼:
<ul>
<li style="text-align:center" class="gjflCur"><a href="javascript:goGjfl('0');">全部</a></li>
<li><a href="javascript:goGjfl('1');">第01類-化學(xué)原料</a></li>
<li><a href="javascript:goGjfl('2');">第02類-顏料油漆</a></li>
<li><a href="javascript:goGjfl('3');">第03類-日化用品</a></li>
<li><a href="javascript:goGjfl('4');">第04類-燃料油脂</a></li>
<li><a href="javascript:goGjfl('5');">第05類-醫(yī)藥</a></li>
<li><a href="javascript:goGjfl('6');">第06類-金屬材料</a></li>
<li><a href="javascript:goGjfl('7');">第07類-機(jī)械設(shè)備</a></li>
<li><a href="javascript:goGjfl('8');">第08類-手工器械</a></li>
<li><a href="javascript:goGjfl('9');">第09類-科學(xué)儀器</a></li>
<li><a href="javascript:goGjfl('10');">第10類-醫(yī)療器械</a></li>
......
</ul>
<form name="hideForm" id="hideForm" action="/search!page.php" method="get">
<input type="hidden" id="pageNo" name="pageNo" value="1"/>
<input type="hidden" id="l" name="l" value="201806061005481578c3lmZ"/>
<input type="hidden" id="gjfls" name="gjfls" value="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"/>
<input type="hidden" id="gjfl" name="gjfl" value="0"/>
<input type="hidden" id="searchKey" name="searchKey" value="APPLE"/>
<input type="hidden" id="st" name="st" value="4"/>
</form>
JQuery代碼:
<script type="text/javascript">
function goGjfl(gjflStr){
$("#pageNo").val("1");
$("#gjfl").val(gjflStr);
$("#hideForm").submit();
}
function jumpPage(pageNo){
$("#pageNo").val(pageNo);
$("#hideForm").submit();
}
function goSearchLog(key){
$("#keywordT").val(key);
$("#stT").val("4");
$("#topF").submit();
}
</script>
模擬請(qǐng)求之后url獲得的地址信息:
http://www.clayfountains.com/search!page.php?pageNo=1&l=201806061005481578c3lmZ&gjfls=1%3B2%3B3%3B4%3B5%3B6%3B7%3B8%3B9%3B10%3B11%3B12%3B13%3B14%3B15%3B16%3B17%3B18%3B19%3B20%3B21%3B22%3B23%3B24%3B25%3B26%3B27%3B28%3B29%3B30%3B31%3B32%3B33%3B34%3B35%3B36%3B37%3B38%3B39%3B40%3B41%3B42%3B43%3B44%3B45&gjfl=1&searchKey=APPLE&st=4
通過(guò)模擬form表單請(qǐng)注,url中獲得參數(shù)也更方便啦!
HTML代碼:
<ul>
<li style="text-align:center" class="gjflCur"><a href="javascript:goGjfl('0');">全部</a></li>
<li><a href="javascript:goGjfl('1');">第01類-化學(xué)原料</a></li>
<li><a href="javascript:goGjfl('2');">第02類-顏料油漆</a></li>
<li><a href="javascript:goGjfl('3');">第03類-日化用品</a></li>
<li><a href="javascript:goGjfl('4');">第04類-燃料油脂</a></li>
<li><a href="javascript:goGjfl('5');">第05類-醫(yī)藥</a></li>
<li><a href="javascript:goGjfl('6');">第06類-金屬材料</a></li>
<li><a href="javascript:goGjfl('7');">第07類-機(jī)械設(shè)備</a></li>
<li><a href="javascript:goGjfl('8');">第08類-手工器械</a></li>
<li><a href="javascript:goGjfl('9');">第09類-科學(xué)儀器</a></li>
<li><a href="javascript:goGjfl('10');">第10類-醫(yī)療器械</a></li>
......
</ul>
<form name="hideForm" id="hideForm" action="/search!page.php" method="get">
<input type="hidden" id="pageNo" name="pageNo" value="1"/>
<input type="hidden" id="l" name="l" value="201806061005481578c3lmZ"/>
<input type="hidden" id="gjfls" name="gjfls" value="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"/>
<input type="hidden" id="gjfl" name="gjfl" value="0"/>
<input type="hidden" id="searchKey" name="searchKey" value="APPLE"/>
<input type="hidden" id="st" name="st" value="4"/>
</form>
JQuery代碼:
<script type="text/javascript">
function goGjfl(gjflStr){
$("#pageNo").val("1");
$("#gjfl").val(gjflStr);
$("#hideForm").submit();
}
function jumpPage(pageNo){
$("#pageNo").val(pageNo);
$("#hideForm").submit();
}
function goSearchLog(key){
$("#keywordT").val(key);
$("#stT").val("4");
$("#topF").submit();
}
</script>
模擬請(qǐng)求之后url獲得的地址信息:
http://www.clayfountains.com/search!page.php?pageNo=1&l=201806061005481578c3lmZ&gjfls=1%3B2%3B3%3B4%3B5%3B6%3B7%3B8%3B9%3B10%3B11%3B12%3B13%3B14%3B15%3B16%3B17%3B18%3B19%3B20%3B21%3B22%3B23%3B24%3B25%3B26%3B27%3B28%3B29%3B30%3B31%3B32%3B33%3B34%3B35%3B36%3B37%3B38%3B39%3B40%3B41%3B42%3B43%3B44%3B45&gjfl=1&searchKey=APPLE&st=4
通過(guò)模擬form表單請(qǐng)注,url中獲得參數(shù)也更方便啦!