<!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容");
}
});
});