ASP.NET jQuery attr()和prop()方法应用举例---实现选择与交换
2021/4/8 22:55:20
本文主要是介绍ASP.NET jQuery attr()和prop()方法应用举例---实现选择与交换,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
①Default.aspx文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script src="jquery.js" type="text/javascript"></script> <style type="text/css"> #pic1 { height: 211px; width: 224px; } #pic2 { height: 213px; width: 216px; margin-top: 0px; } </style> </head> <body> <form id="form1" runat="server"> <div> <img id="pic1" src="images/1.jpg" />  <img id="pic2" src="images/2.jpg" /><br/> <hr /> <input type="checkbox" name="goods" value="商品1" /> 商品1 <input type="checkbox" name="goods" value="商品2" /> 商品2 <input type="checkbox" name="goods" value="商品3" /> 商品3 <input type="checkbox" name="goods" value="商品4" /> 商品4<br /> <hr /> <input type="button" value="交换图片" οnclick="changepic()" /> <input type="button" value ="全选" οnclick="selectall()" /> <input type="button" value ="反选" οnclick="reselect()" /> <input type="button" value ="全选并禁用" οnclick="disselect()" /> <input type="button" value ="取消禁用" οnclick="enable()" /> </div> <script type="text/javascript"> function changepic() { var picsrc = $("#pic1").attr("src"); if (picsrc.indexOf("1.jpg") != -1) { $("#pic1").attr("src", "images/2.jpg"); $("#pic2").attr("src", "images/1.jpg"); } else { $("#pic1").attr("src", "images/1.jpg"); $("#pic2").attr("src", "images/2.jpg"); } } function selectall() { $("input[type='checkbox']").prop("checked", true); } function reselect() { $("input[type='checkbox']").prop("checked", function (index, oldval) { return !oldval; }); } function disselect() { $("input[type='checkbox']").prop({ checked: true, disabled: true }); } function enable() { $("input[type='checkbox']").attr("disabled", false); } </script> </form> </body> </html>
②效果图及说明:
Ⅰ.交换
选择“交换图片”之后,如下图所示:
Ⅱ.选择
ⅰ点击“路飞”“索隆”之后再点击“全选”,如下图所示:
ⅱ点击“路飞”“索隆”之后再点击“反选”,如下图所示:
ⅲ点击“全选并禁用”,如下图所示:
ⅳ点击“取消禁用”,如下图所示:
这篇关于ASP.NET jQuery attr()和prop()方法应用举例---实现选择与交换的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#
- 2024-01-24Advanced .Net Debugging 1:你必须知道的调试工具
- 2024-01-24.NET集成IdGenerator生成分布式全局唯一ID
- 2024-01-23用CI/CD工具Vela部署Elasticsearch + C# 如何使用
- 2024-01-23.NET开源的简单、快速、强大的前后端分离后台权限管理系统