2014-08-12 15:42:00
一. 重置表单
Java代码
- $("form").each(function(){
- .reset();
- });
1:得到值:
Java代码
- var textval = $("#text_id").attr("value");
Java代码
- var textval = $("#text_id").val();
Java代码
- $("#text_id").attr("value",'');
Java代码
- $("#text_id").attr("value",'test');
1:回填赋值
Java代码
- <span>性别:</span>
- <input id="sex" name="sex" type="radio" value="1"/> 男
- <input id="sex" name="sex" type="radio" value="0"/> 女
- <script language=javascript>
- $(document).ready(function() {
- $('[name="sex"]:radio').each(function() {
- if (this.value == 0) {
- this.checked = true;
- }
- });
- });
- </script>
Java代码
- var valradio = $("input[@type=radio][@checked]").val();
Java代码
- var item = $('input[@name=items][@checked]').val();
Java代码
- $("input[@type=radio]").attr("checked",'2');
Java代码
- var item = $('input[@name=items][@checked]').val();
Java代码
- $('input[@name=items]').get(1).checked = true;
Java代码
- var checkboxval = $("#checkbox_id").attr("value");
Java代码
- $("#chk_id").attr("checked",'');
Java代码
- $("#chk_id").attr("checked",true);
Java代码
- if($("#chk_id").attr('checked')==true) {
- ...
- }
1:获取下拉列表的值
Java代码
- var selectval = $('#select_id').val();
Java代码
- <select name="sex" id="sex">
- <option value="">请选择</option>
- <option value="0">男</option>
- <option value="1">女</option>
- </select>
- $(document).ready(function() {
- $("#sex").attr("value", ${filter.sex});
- });
Java代码
- <select id="prStatCd" name="prStatCd">
- <option value="">--请选择--</option>
- <option value="10">新建</option>
- <option value="20">确认</option>
- <option value="91">否决</option>
- </select>
- $("select[@name=prStatCd] option").each(function(k,v) {
- if ($(this).val() == "${param.prStatCd}") {
- $('#prStatCd')[0].selectedIndex = k;
- return false;
- }
- });
Java代码
- $("#select_id").attr("value",'test');
Java代码
- $("<option value='test'>test</option><option value='test2'>test2</option>").appendTo("#select_id")
Java代码
- $("#select_id").empty();
Java代码
- var item = $("select[@name=items] option[@selected]").text();
Java代码
- $('#select_id')[0].selectedIndex = 1;
Java代码
- $(function() {
- $("#isStu").click(function() {
- if ($(this).attr("checked")) {
- $(".ct7").show();
- $(".ct7 *[required]").attr("required", true);
- } else {
- $(".ct7").hide();
- $(".ct7 *[required]").attr("required", false);
- }
- })
- $("#isStu").attr("checked", true);
- $(".level").click(function() {
- var typeValue = $(".level").index(this);
- if (typeValue == 0) {
- $("#classType").empty();
- $("<option value=''>请选择班型</option>").appendTo("#classType");
- $("<option>大学英语四级VIP全程班</option>").appendTo("#classType");
- } else {
- $("#classType").empty();
- $("<option value=''>请选择班型</option>").appendTo("#classType");
- $("<option>大学英语六级VIP全程班</option>").appendTo("#classType");
- }
- });
- $(".level").click();
- });
Java代码
- 考试级别:
- <select id="type" class="cet" name="type">
- <option value="0">全部</option>
- <option value="1">四级</option>
- <option value="2">六级</option>
- </select>
- <br>
- 所选班型:
- <select id="classType" class="cet" name="classType"></select>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#type").change(function() {
- $("#classType").empty();
- var value = $(this).val();
- if (value == 1) {
- $("<option value=''>请选择班型</option>").appendTo("#classType");
- $("<option>大学英语四级VIP全程班</option>").appendTo("#classType");
- $("<option>大学英语四级精品全程班</option>").appendTo("#classType");
- } else if (value == 2) {
- $("<option value=''>请选择班型</option>").appendTo("#classType");
- $("<option>大学英语六级VIP全程班</option>").appendTo("#classType");
- $("<option>大学英语六级精品全程班</option>").appendTo("#classType");
- }
- })
- });
- </script>
Java代码
- <script type="text/javascript">
- function del() {
- if(confirm("确定删除吗?")){
- window.location = "/shaifenUserServletMaintain/-1?_method=updateStatus&ids=" + getIds();
- }
- }
- function shtg() {
- window.location = "/shaifenUserServletMaintain/1?_method=updateStatus&ids=" + getIds();
- }
- function cxsh() {
- window.location = "/shaifenUserServletMaintain/2?_method=updateStatus&ids=" + getIds();
- }
- function getIds() {
- var ids = "";
- $("input[name='id']").each(function() {
- if (this.checked) {
- if (ids != "") {
- ids += ",";
- }
- ids += this.value;
- }
- });
- return ids;
- }
- $("document").ready(function() {
- $("#all").click(function() {
- if (this.checked) {
- $("input[name='id']").each(function() {
- this.checked = true;
- });
- $("#qx").text("反选");
- } else {
- $("input[name='id']").each(function() {
- this.checked = false;
- });
- $("#qx").text("全选");
- }
- });
- })
- </script>
- <div class="m1">
- <a href="javascript:del()">批量删除</a>
- <a href="javascript:shtg()">批量审核通过</a>
- <a href="javascript:cxsh()">批量审核不通过</a>
- </div>
- <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab1 m1" id="tab2">
- <tr>
- <th width="40">
- <span id="qx">全选</span>
- <input type="checkbox" id="all" name="all">
- </th>
- <th width="60" align="center">ID</th>
- <th width="60" align="center">userId</th>
- <th width="120" align="center">姓名</th>
- <th width="100" align="center">级别</th>
- </tr>
- <c:forEach var="item" items="${list}" varStatus="status">
- <tr>
- <td align="center"><input type="checkbox" id="id" value="${item.id}" name="id"/></td>
- <td align="center">${item.id}</td>
- <td>${item.userId}</td>
- <td><c:out value="${item.realName}" escapeXml="true"/></td>
- </tr>
- </c:forEach>
- </table>
方案1 : 加在 按钮上
Java代码
- $("document").ready(function() {
- $("input:submit").each(function() {
- $(this).click(function() {
- setdisabled(this,true);
- return true;
- });
- });
- function setdisabled(obj) {
- setTimeout(function() {
- obj.disabled = true;
- }, 100);
- }
- })
方案2:加在 form 上
Java代码
- $("document").ready(function() {
- $("#form1").submit(function(){
- setdisabled($("#tj"));
- });
- function setdisabled(obj) {
- setTimeout(function() {
- obj.disabled = true;
- }, 100);
- }
- })
方案 3:
Java代码
- $("document").ready(function() {
- $("#form1").submit(function() {
- $("#tj").attr("disabled","true");
- });
- })
Java代码
- <script type="text/javascript">
- var flag_submit = false;
- $(document).ready(function() {
- $("#form1").submit(function() {
- if(flag_submit){
- return false;
- }
- flag_submit = true;
- });
- })
- </script>
评论 (0)