jQuery设置和获取HTML、文本和值
来源:互联网 发布:access如何输入数据 编辑:程序博客网 时间:2024/05/18 18:17
<script type="text/javascript"> //<![CDATA[ $(function(){ //获取<p>元素的HTML代码 $("input:eq(0)").click(function(){ alert( $("p").html() ); }); //获取<p>元素的文本 $("input:eq(1)").click(function(){ alert( $("p").text() ); }); //设置<p>元素的HTML代码 $("input:eq(2)").click(function(){ $("p").html("<strong>你最喜欢的水果是?</strong>"); }); //设置<p>元素的文本 $("input:eq(3)").click(function(){ $("p").text("你最喜欢的水果是?"); }); //设置<p>元素的文本 $("input:eq(4)").click(function(){ $("p").text("<strong>你最喜欢的水果是?</strong>"); }); //获取按钮的value值 $("input:eq(5)").click(function(){ alert( $(this).val() ); }); //设置按钮的value值 $("input:eq(6)").click(function(){ $(this).val("我被点击了!"); }); }); //]]> </script>
<script type="text/javascript"> //<![CDATA[ $(function(){ $("#address").focus(function(){ // 地址框获得鼠标焦点 var txt_value = $(this).val(); // 得到当前文本框的值 if(txt_value=="请输入邮箱地址"){ $(this).val(""); // 如果符合条件,则清空文本框内容 } }); $("#address").blur(function(){ // 地址框失去鼠标焦点 var txt_value = $(this).val(); // 得到当前文本框的值 if(txt_value==""){ $(this).val("请输入邮箱地址");// 如果符合条件,则设置内容 } }) $("#password").focus(function(){ var txt_value = $(this).val(); if(txt_value=="请输入邮箱密码"){ $(this).val(""); } }); $("#password").blur(function(){ var txt_value = $(this).val(); if(txt_value==""){ $(this).val("请输入邮箱密码"); } }) }); //]]> </script>
<script type="text/javascript"> //<![CDATA[ $(function(){ $("#address").focus(function(){ // 地址框获得鼠标焦点 var txt_value = $(this).val(); // 得到当前文本框的值 if(txt_value==this.defaultValue){ $(this).val(""); // 如果符合条件,则清空文本框内容 } }); $("#address").blur(function(){ // 地址框失去鼠标焦点 var txt_value = $(this).val(); // 得到当前文本框的值 if(txt_value==""){ $(this).val(this.defaultValue);// 如果符合条件,则设置内容 } }) $("#password").focus(function(){ var txt_value = $(this).val(); if(txt_value==this.defaultValue){ $(this).val(""); } }); $("#password").blur(function(){ var txt_value = $(this).val(); if(txt_value==""){ $(this).val(this.defaultValue); } }) }); //]]> </script>
<script type="text/javascript"> //<![CDATA[ $(function(){ //设置单选下拉框选中 $("input:eq(0)").click(function(){ $("#single").val("2"); }); //设置多选下拉框选中 $("input:eq(1)").click(function(){ $("#multiple").val(["选择2号", "选择3号"]); }); //设置单选框和多选框选中 $("input:eq(2)").click(function(){ $(":checkbox").val(["check2","check3"]); $(":radio").val(["radio2"]); }); }); //]]> </script>
<script type="text/javascript"> //<![CDATA[ $(function(){ //设置单选下拉框选中 $("input:eq(0)").click(function(){ $("#single option").removeAttr("selected"); //移除属性selected $("#single option:eq(1)").attr("selected",true); //设置属性selected }); //设置多选下拉框选中 $("input:eq(1)").click(function(){ $("#multiple option").removeAttr("selected"); //移除属性selected $("#multiple option:eq(2)").attr("selected",true);//设置属性selected $("#multiple option:eq(3)").attr("selected",true);//设置属性selected }); //设置单选框和多选框选中 $("input:eq(2)").click(function(){ $(":checkbox").removeAttr("checked"); //移除属性checked $(":radio").removeAttr("checked"); //移除属性checked $(":checkbox[value=check2]").attr("checked",true);//设置属性checked $("[value=check3]:checkbox").attr("checked",true);//设置属性checked $("[value=radio2]:radio").attr("checked",true);//设置属性checked }); }); //]]> </script>
:checkbox 表示属性为checkbox
源文地址:点击打开链接
0 0
- jquery设置和获取html,文本,值
- jQuery设置和获取HTML、文本和值
- jQuery设置和获取HTML、文本和值
- jQuery设置和获取HTML、文本和值
- jQuery设置和获取HTML、文本和值
- jQuery设置和获取HTML、文本和值
- jQuery设置和获取HTML、文本和值
- jQuery(3-9)设置或获取HTML、文本和值
- 设置和获取html、文本和值
- jQuery设置和获取HTML、文本和值和Javascript获取HTML静态页面参数传递值示例
- 3.2.10: jQuery的DOM操作之设置和获取HTML、文本和值
- 锋利jquery----3-10设置和获取HTML,文本和值
- Jquery中的DOM操作 (七.设置和获取HTML,文本和值)
- jquery获取选中的文本和值
- Jquery—获取和设置html内容和属性
- jquery获取HTML,文本
- jQuery获取select元素option的文本值和value值及回填设置值
- jquery获取和设置select选中的值/文本/索引及选中事件
- yum命令详解
- Sublime Text 使用介绍/全套快捷键及插件推荐
- 正则表达式过滤中文
- Java的位运算
- ubuntu12.10可用更新源
- jQuery设置和获取HTML、文本和值
- iOS静态库相关-封装lib
- bat之for循环
- Hibernate的update建表
- C语言拾零(to be continued)
- linux ln 命令使用参数详解(ln -s 软链接)
- Mac OS X 右盘菜单的Open With(打开方式)中多余的菜单项的清除
- Manacher算法--O(n)回文子串算法
- UVa 11021 - Tribles (概率DP)