jquery学习历程!第一节!

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").click(function(){
     $(this).html("内容");
    
   // window.location.reload()      // 刷新页面
  });
});
</script>
</head>
<body>
<p>如果您点击我,我会消失。</p>
<p>点击我,我会消失。</p>
<p>也要点击我哦。</p>
</body>
</html>

 

--  页面加载完成后,自动增加点击事件!

 

点击事件修改显示汉字。

 

 

--  根据不同ID ,判断不同的显示方式,没成功!------大神给指条明路!!!!!!!

引用别人的文字:

显示好友列表时,在显示好友名字的<p></p>元素中设置:<p id="p${friend.friendId}"></p>,这样js文件就可以动态获取<p></p>元素的id,并顺利通过text()方法赋值$("#p"+userId).text(name);    

看到了上面这段话,没用 明白!

<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
$(document).ready(function(){
  $("p").click(function(){
   if ($(this).id == p_a){
     $(this).html("内容");
     }    elseif ($(this).id ==p_b){
     $(this).html("内容1");
     }else   if ($(this).id ==p_c){
     $(this).html("内1容");
     }

  });
});
</script>
</head>
<body>
<p id="p_a">如果您点击我,我会消失。</p>
<p id="p_b">点击我,我会消失。</p>
<p id="p_c">也要点击我哦。</p>
</body>
</html>

 

 

 

-----------搞定了!

$(document).ready(function(){
    
  $("p").click(function(){
      alert($(this).attr('id'));
      if($(this).attr('id')=="paa"){
         $(this).text("内容");
      }
      if($(this).attr('id')=='pbb'){
             $(this).html("内1容");
      }
      if($(this).attr('id')=='pcc'){
             $(this).html("内2容");
      }
     
        
  });
});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值