js高手請(qǐng)進(jìn)
頁(yè)面中一個(gè)文本框;rnrnbody有一個(gè)onclick事件,文本框有一個(gè)onfocus事件,如何讓這兩個(gè)事件不沖突?rn比如:激發(fā)onfocus 事件時(shí),必須要點(diǎn)一下是吧,可這樣一來(lái),body的onclick事件也激發(fā)了!本人想onfocus的時(shí)候,不要同時(shí)也激發(fā)body的onclick,有沒(méi)有辦法呢?已經(jīng)OK,把下面的完全復(fù)制測(cè)試::
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無(wú)標(biāo)題文檔</title>
<script language="javascript">
function getOnclick()
{
alert("這個(gè)是onclick事件");
}
function getOnfocus()
{
document.getElementById("mybody").onclick="";
alert("這個(gè)是onfocus事件");
}
function getOnblur()
{
document.getElementById("mybody").onclick=getOnclick;
alert(document.getElementById("mybody").onclick);
// alert("這個(gè)是Onblur事件");
}
</script>
</head>
<body onclick="getOnclick()" id="mybody">這個(gè)是onclick事件
<input type="text" onfocus="getOnfocus()" onblur="getOnblur()"></body>
</html>
<body onclick="alert(1)">
<input onClick="event.cancelBubble=true;"/>
</body>
這樣就可以
onfocus做完以后 return false,那么后面就不做了
JS高手請(qǐng)進(jìn)!
接觸JS不太久 問(wèn)點(diǎn)問(wèn)題rnrn<script type="text/javascript">rnvar flag= window.location.href.match(/\?flag=([^\&]*)/i);rnflag = flag[1];rnrnfunction _cancel() {rn window.close();rn}rnfunction insetIMG(_sVal) {rn if(_sVal == "") return;rn var html = "";rn parent.insertHtml(html , flag);rn parent.document.getElementById(flag+"box").className="box";rn}rnrnfunction insertIMAGE(src) {rn if((!/^http:\/\//i.test(src)) && (!/^\//i.test(src))){rn src = x27http://x27+src;rn }rnrnvar oRTE = parent.getFrameNode(flag);rn oRTE.focus();rn oRTE.document.execCommand(x27insertIMAGEx27, false, src);rn oRTE.focus();rnrn parent.document.getElementById(flag+"box").className = "box";rn}rn</script>rnrnrn" border="0" onMouseOver="insertIMAGE(this.src)" onmouseout="window.parent.document.getElementById(x27cbax27).style.display=x27nonex27" alt="用戶(hù)上傳的圖片">rnrn