zoukankan      html  css  js  c++  java
  • 函数

    函数:

    val()
    $(选择器).val():无参形式,获取第一个dom对象的value属性值
    $(选择器).val(值):有参形式,对数组中所有dom对象的value属性值进行统一赋值

    text()
    $(选择器).text(),读取数组中所有dom对象的文字显示内容,得到的内容拼接成一个字符串返回
    $(选择器).text(值),对数组中所有dom对象的文字显示内容进行统一赋值

    attr
    $(选择器).attr(“属性名”):获取dom数组中第一个对象的属性值
    $(选择器).attr(“属性名”,“值”):对数组中所有dom对象的属性设为新值

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title>函数</title>
    		<style type="text/css">
    			div{
    				background-color: goldenrod;
    			}
    			img{
    				height: 100px;
    			}
    		</style>
    		<script type="text/javascript" src="js/jquery-3.4.1.js">
    			
    		</script>
    		<script type="text/javascript">
    			$(function(){
    				$("#btn1").click(function(){
    					alert($(":text").val());
    				})
    				
    				$("#btn2").click(function(){
    					$(":text").val("设置所有值为hello");
    				})
    				
    				$("#btn3").click(function(){
    					alert($("div").text());
    				})
    				
    				$("#btn4").click(function(){
    					alert($("img").attr("src"));
    				})
    				
    				$("#btn5").click(function(){
    					$("img").attr("src","img/index2.jpg")
    				})
    			})
    		</script>
    	</head>
    	<body>
    		<input type="text" value="text1" /><br />
    		<input type="text" value="text2" /><br />
    		<input type="text" value="text3" /><br />
    		<br />
    		<div>我是div1</div><br />
    		<div>我是div2</div><br />
    		<div>我是div3</div><br />
    		
    		<img src="img/index.jpg" id="image1"/>
    		
    		<br />
    		
    		<input type="button" id="btn1" value="获取第一个文本框的值"/>
    		<br />
    		
    		<input type="button" id="btn2" value="设置所有文本框的值为hello"/>
    		<br />
    		
    		<input type="button" id="btn3" value="获取div文本"/>
    		<br />
    		
    		<input type="button" id="btn4" value="获取div文本"/>
    		<br />
    		
    		<input type="button" id="btn5" value="获取div文本"/>
    	</body>
    	
    </html>
    
  • 相关阅读:
    Spring Aware源码
    Spring 后置处理器源码
    Java8 Optional
    几种自定义Spring生命周期的初始化和销毁方法
    Spring通过@Autowired获取组件
    Spring的组件扫描注解
    Spring通过注解注入外部配置文件
    [CSP-S模拟测试92]题解
    [笔记乱写]关于数论函数(关于卷积的一些证明+杜教筛)
    我觉得我就是[数据删除]
  • 原文地址:https://www.cnblogs.com/ethnic/p/14523396.html
Copyright © 2011-2022 走看看