js 常用插件
来源:互联网 发布:最好的我们网络剧网盘 编辑:程序博客网 时间:2024/05/21 19:30
文本输入框 计算器
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题</title> <script type="text/javascript"> function sum(obj) { var a = document.getElementById("a"); var b = document.getElementById("b"); var s = document.getElementById("sum"); if(a.value === "" || b.value === "") { return; } s.value = parseInt(a.value) + parseInt(b.value); } </script> </head> <body> <input type="text" id="a" onkeyup="sum(this);" /> <input type="text" id="b" onkeyup="sum(this);" /> <input type="text" id="sum" /> </body></html>
js全选
<SCRIPT type="text/javascript">$(document).ready(function() { $("#checkedAll").click(function(){ //try{ if($(this).attr("checked") == true){ //check all $("input[name='checkbox_name']").each(function(){ $(this).attr("checked",true); }); }else{ $("input[name='checkbox_name']").each(function(){ $(this).attr("checked",false); }); } //}catch(e){ //alert(e.description+e.name+e.message) //} });});</SCRIPT> <div class="components-list"> <input type="checkbox" name="checkbox_name" id="checkbox_name_1" />1<br /> <input type="checkbox" name="checkbox_name" id="checkbox_name_2" />2<br /> <input type="checkbox" name="checkbox_name" id="checkbox_name_3" />3<br /> <input type="checkbox" name="checkbox_name" id="checkbox_name_4" />4<br /> <input type="checkbox" name="checkedAll" id="checkedAll"/>全选/取消全选 </div>
jQuery获取Select选择的Text和Value:
语法解释:1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text3. var checkValue=$("#select_id").val(); //获取Select选择的Value4. var checkIndex=$("#select_id ").get(0).selectedIndex; //获取Select选择的索引值5. var maxIndex=$("#select_id option:last").attr("index"); //获取Select最大的索引值jQuery设置Select选择的 Text和Value:语法解释:1. $("#select_id ").get(0).selectedIndex=1; //设置Select索引值为1的项选中2. $("#select_id ").val(4); // 设置Select的Value值为4的项选中3. $("#select_id option[text='jQuery']").attr("selected", true); //设置Select的Text值为jQuery的项选中
选中checkbox:
//jQuery 1.6+$("#checkboxID").prop("checked", true);$("#checkboxID").prop("checked", false);//jQuery 1.5 and below$('#checkboxID').attr('checked','checked')$('#checkboxID').removeAttr('checked')
jQuery中event.preventDefault() 与 return false 的区别
//Demo1 event.preventDefault()$('a').click(function (e) { // custom handling here e.preventDefault();});//Demo2 return false$('a').click(function () { // custom handling here return false;};
合并两个Array并去掉重复项
Array.prototype.unique = function() { var a = this.concat(); for(var i=0; i<a.length; ++i) { for(var j=i+1; j<a.length; ++j) { if(a[i] === a[j]) a.splice(j, 1); } } return a;};//Demovar array1 = ["a","b"];var array2 = ["b", "c"];var array3 = array1.concat(array2).unique();// ["a","b","c"]
取数组中的最小值和最大值
var arr = new Array();arr[0] = 100;arr[1] = 0;arr[2] = 50;var min = Math.min.apply(null, arr), max = Math.max.apply(null, arr);
0 0
- 项目常用js插件
- 常用的js插件
- js常用插件
- js 常用插件
- js常用插件
- js常用插件
- 常用JS插件
- 前端常用js插件总汇
- Node.js 常用插件集合
- 记录几个常用的js插件
- 常用且实现的JS小插件
- js常用插件网络路径总结
- JS常用(通用)功能(插件)
- 第7章 Vue.js常用插件
- sublime text3--js智能提示插件以及其他常用插件
- 轻量级JS Cookie插件js-cookie 常用方法
- 自己总结的一些比较常用的js插件
- 收集整理自己常用的几个JS插件
- php 提交表单
- laravel安装 笔记
- Framework did not have a CFBundleIdentifier in its Info.plist
- 常用 ajax js 表单
- 立FLAG
- js 常用插件
- 8大排序算法动态图文讲解
- 上传图片
- 图片上传直接显示
- 最全的常用正则表达式
- 2套 三级联动
- 下拉加载 只能搜索
- Spring boot 中使用swagger-ui实现 restful-api
- 将博客搬至CSDN