onmouseover、onmouseout、onclick 事件上的图像更改

发布于 2024-07-23 02:47:17 字数 2602 浏览 12 评论 0原文

我有两个图像,img1 和 img2。 我的代码:

function roll(id,img_name,event_name,img_id)
 {
    var state ;
    if(event_name == 'mouseover')
    { state = false;rollover();}
    else if(event_name == 'mouseout')
    {state = false;rollout();}
    else if(event_name == 'onClick')
    {alert(event_name);state = true;showdata(id,img_name,state);}
    else
    {showDIV(id);}
    
   function rollover()
   {
        if(state == false)
        {
            var imgpath='image_file/'; 
            document[img_name].src =imgpath + img_name + '_over.png';
        }
   }
   function rollout()
   {
        if(state == false)
        {
            var imgpath='image_file/'; 
            document[img_name].src = imgpath + img_name + '.png';
        }
   }
    function showDIV(id)
    {  
        var div = document.getElementById(id);
	    if ( div.style.display != "none" ) 
	    {
		    div.style.display = "none";
		    document[img_name].src='downarrow.png';
    		
	    }
	    else 
	    {
		    div.style.display = "block";
		    document[img_name].src='uparrow.png';
	    }
    }
    function showdata(id,img_name,state,img_id)
    {alert(state);
        if(state == true)
        {
            var imgpath='image_file/'+ img_name;
            var div = document.getElementById(id);
	        if ( div.style.display != "none" ) 
	        { alert('none' +state);
	            document.getElementsByName(img_name).src =imgpath + '.png';
		        div.style.display = "none";
	        }
	        else 
	        {   alert('block :' +state);
	            document.images[img_name].src='image_file/journey_icon_over.png';
		        div.style.display = "block";
	        }
	    }
    }
}
    <tr>
    <td valign="top" width="100%">
    <img id="img1"  name="journey_icon" src="image_file/journey_icon.png"  alt="Journey  Report" onmouseover="roll('JourneyReport','journey_icon','mouseover')" onmouseout="roll('JourneyReport','journey_icon','mouseout')" onclick="roll('JourneyReport','journey_icon','onClick',this.id)" />
    <div id="JourneyReport" style="display:none;" class="divbackground">
    <uc1:ReportControl ID="JourneyControl" runat="server" />
    </div>
    </td>
    </tr>

要求是,我需要在鼠标悬停时使用 img1 ,在鼠标移出时使用 img2 ,这工作正常,但是在单击时,我需要打开 div 并冻结 img2 ,然后再次单击 div 消失,并且 onmouseover 和 onmouseout 状态正常工作。 目前的问题是,单击时会出现 div,但 onmouse over 和 onmouseout 函数也会被触发。

库什

I have a two images say, img1 and img2.
My Code :

function roll(id,img_name,event_name,img_id)
 {
    var state ;
    if(event_name == 'mouseover')
    { state = false;rollover();}
    else if(event_name == 'mouseout')
    {state = false;rollout();}
    else if(event_name == 'onClick')
    {alert(event_name);state = true;showdata(id,img_name,state);}
    else
    {showDIV(id);}
    
   function rollover()
   {
        if(state == false)
        {
            var imgpath='image_file/'; 
            document[img_name].src =imgpath + img_name + '_over.png';
        }
   }
   function rollout()
   {
        if(state == false)
        {
            var imgpath='image_file/'; 
            document[img_name].src = imgpath + img_name + '.png';
        }
   }
    function showDIV(id)
    {  
        var div = document.getElementById(id);
	    if ( div.style.display != "none" ) 
	    {
		    div.style.display = "none";
		    document[img_name].src='downarrow.png';
    		
	    }
	    else 
	    {
		    div.style.display = "block";
		    document[img_name].src='uparrow.png';
	    }
    }
    function showdata(id,img_name,state,img_id)
    {alert(state);
        if(state == true)
        {
            var imgpath='image_file/'+ img_name;
            var div = document.getElementById(id);
	        if ( div.style.display != "none" ) 
	        { alert('none' +state);
	            document.getElementsByName(img_name).src =imgpath + '.png';
		        div.style.display = "none";
	        }
	        else 
	        {   alert('block :' +state);
	            document.images[img_name].src='image_file/journey_icon_over.png';
		        div.style.display = "block";
	        }
	    }
    }
}
    <tr>
    <td valign="top" width="100%">
    <img id="img1"  name="journey_icon" src="image_file/journey_icon.png"  alt="Journey  Report" onmouseover="roll('JourneyReport','journey_icon','mouseover')" onmouseout="roll('JourneyReport','journey_icon','mouseout')" onclick="roll('JourneyReport','journey_icon','onClick',this.id)" />
    <div id="JourneyReport" style="display:none;" class="divbackground">
    <uc1:ReportControl ID="JourneyControl" runat="server" />
    </div>
    </td>
    </tr>

the requirement is that, i need img1 on mouseover and img2 on mouseout, which is working fine, but on Click, i need the div to be opened and img2 get frozen and in again click div disappears and onmouseover and onmouseout states working. Currently the problem is, on click, the div appears but the onmouse over and onmouseout functions are also fired.

Khushi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

錯遇了你 2024-07-30 02:47:18

你需要阻止事件的发酵。 在 onclick 代码末尾添加以下内容:
window.events.cancelBubble = true; 看看它对您有何作用。 我不确定这是否会停止 mouseovermouseout 事件,但请尝试一下。

You need to stop the events from bubbling up. At the end of your onclick code, add this:
window.events.cancelBubble = true; and see how that works for you. I'm not sure this will stop the mouseover and mouseout events, but give it a whirl.

岁吢 2024-07-30 02:47:18

嘿,我在逻辑的帮助下成功完成了该事件......
我的条件完全不同..

onmouseover 事件 = 编写函数来显示第一个图像

onmouseout 事件 = 编写函数来显示单击后要显示的图像

onclick 事件 = 还保存最后单击的图像(在隐藏字段中的某处)
调用函数“编写函数来显示要显示的图像
点击后。 snd 函数”,& 说返回 false;

仅此而已
不要在 mouseout 事件上获取 img url 作为参数,而是编写 Js fun 让它在“保存上次单击的图像(即 onclick 事件上使用的第一个 fun”)中获取 img url

我认为这会有所帮助你

Hey I have managed that event with help of logic...
My conditions are quit different..

onmouseover event = write function to display First Image

onmouseout event = write function to display Image that you want to display after click

onclick event = Save last clicked image (somewhere in hidden field) also
call function "write function to display Image that you want to display
after click.ie. snd function", & say return false;

Thats all
Do not get img url on mouseout event as a parameter instead write Js fun for it to get img url in "Save last clicked image (ie. first fun used on onclick event")

I think this will help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文