使用jquery怎么根据ID给元素赋值
在jsp中怎么使用jquery根据ID给元素赋值?
操作方法
- 01
编写页面: <input type="button" value="按价格" name="score" id="bypic" onclick="bypicord()"> <input type="hidden" value="desc" id="ordercon">
- 02
编写js: <script type="text/javascript"> function bypicord(){ var reorder = $("#ordercon").val(); if("desc" == reorder){ $("#ordercon").val("asc"); var url = "<%=path %>/product/listproduct.action?uid="+${sessionScope.user.id}+"&sort=price&ten=Y&FROMBUS=Y&order=asc"; gotoquery(url); //window.location.href =gotoquery('url'); }else { $("#ordercon").val("desc"); reorder = "desc"; var url = "<%=path %>/product/listproduct.action?uid="+${sessionScope.user.id}+"&sort=price&ten=Y&FROMBUS=Y&order=desc"; gotoquery(url); } } </script> 其中的:$("#ordercon").val("asc");就是给id为ordercon的元素赋值
- 03
效果如下: