个人笔记之jQuery的获取内容或属性

个人笔记之jQuery的获取内容或属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
    <p id="test1">超级变变变</p>
    <p id="test2">大大变</p>
    <button id="btn1">显示/设置文本</button>
    <button id="btn2">显示/设置HTML</button>
    <button id = "btn3">显示/设置值</button>
    <input type="text" id="inpu" value="输一哈值嘛">
    <p><a href="###" id="href"></a></p>
    <button id="btn4">显示href值</button>
    <p><a href="http://www.runoob.com" id="runoob">菜鸟教程</a></p>
    <button id="btn5">修改href和title</button>
    <script>
        $(document).ready(function(){
            $("#btn1").click(function(){
                $("#test1").text(function(i,origText){
                    return "旧文本:" +origText+ "    新文本:头秃了,也变强了(index:"+i+")";
                });  
            });
            $("#btn2").click(function(){
                $("#test2").html(function(i,origText){
                    return "旧html:" +origText+"<br>"+ "新html:<b>更强了</b>(index:"+i+")";
                });   
            });
            $("#btn3").click(function(){
                $("#inpu").val("莫憨起,喊你输一哈值");
            });
            $("#btn4").click(function(){
                alert("href值为:"+$("#href").attr("href"));
            });
            $("#btn5").click(function(){
                $("#runoob").attr({
                    "href":"http://www.runoob.com/jquery",
                    "title":"jQuery 教程"
                });
                titl = $("#runoob").attr('title');
                $("#runoob").html(titl);
            });
        });
    </script>
</body>
</html>

.text() 改文本
.val()改输入值 和 input 结合使用
.html() 引入或展示相关标签
.attr(“url”)掌握它的修改链接以及名字

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值