<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>e </title>
</head>
<body>
123
</body>
</html>我希望选中123的时候触发一个事件如alert('a');
ps(选中页面上任何一个段文字都会触发这个事件)
如何写?????????
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>e </title>
</head>
<body>
123
</body>
</html>我希望选中123的时候触发一个事件如alert('a');
ps(选中页面上任何一个段文字都会触发这个事件)
如何写?????????
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>e </title>
<script>
window.onload=function(){
//MSIE
if(document.all){
document.attachEvent('onclick',function(){
alert('a');
});
}else{
document.addEventListener('click',function(){
alert('a');
},false);
}
}
</script>
</head>
<body>
123
</body>
</html>
<html>
<head>
<title>e </title>
<script>
window.onload=function(){
var ps = document.getElementsByTagName("p");
for(var i=0;i<ps.length;i++){
ps[i].onclick = function(){
alert(this.innerText);
}
}
}
</script>
</head>
<body>
<p>123
<p>456
</body>
</html> 如果针对段落的话,那就吧文本置入段落中