我希望该行保持正确的类别

发布于 2025-01-07 23:55:45 字数 293 浏览 0 评论 0原文

我将其用于行颜色:

 echo"<tr class=\"normal\" onClick=\"this.className='normalselected'\" 
           onmouseover=\"this.className='normalon'\" 
           onmouseout=\"this.className='normal'\">\n";

当您移动时它起作用,当您单击时它起作用仅当我移动到另一行时它才恢复正常。

我怎样才能改变这个?

I use this for the row colors:

 echo"<tr class=\"normal\" onClick=\"this.className='normalselected'\" 
           onmouseover=\"this.className='normalon'\" 
           onmouseout=\"this.className='normal'\">\n";

It works when you move over, it works when you click only when I move to another row it goes back to normal.

How can I change this?

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

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

发布评论

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

评论(3

阿楠 2025-01-14 23:55:45

那是因为 onmouseout 让它恢复正常;你需要的是记住你点击的时间。虽然这不是一个“好的”解决方案,但它应该

在 css 中

.normal-clicked,
.normal-over { 
     /* whatever needs to go here */
}
.normal {
     /* whatever needs to go here */
}

执行您想要的操作,然后在 php 中执行

?>
<script type="text/javascript">
    function handleClick( el ){
        if ( el.className == 'normal-clicked' ){
            el.className = 'normal';
        }
        else {
            el.className = 'normal-clicked';
        }
    }
    function handleMouseOver( el ){
        el.className = 'normal-over';
    }
    function handleMouseOut( el ){
        if ( el.className == 'normal-over' ){
            el.className = 'normal';
        }
    }
</script>
<?php
echo '<tr class="normal" onclick="handleClick(this);" onmouseover="handleMouseOver(this);" onmouseout="handleMouseOut(this);">', "\n";

that's because onmouseout put's it back to normal; what you need is to remember when you clicked. although this is not a "nice" solution it should do what you want

In your css

.normal-clicked,
.normal-over { 
     /* whatever needs to go here */
}
.normal {
     /* whatever needs to go here */
}

Then in the php

?>
<script type="text/javascript">
    function handleClick( el ){
        if ( el.className == 'normal-clicked' ){
            el.className = 'normal';
        }
        else {
            el.className = 'normal-clicked';
        }
    }
    function handleMouseOver( el ){
        el.className = 'normal-over';
    }
    function handleMouseOut( el ){
        if ( el.className == 'normal-over' ){
            el.className = 'normal';
        }
    }
</script>
<?php
echo '<tr class="normal" onclick="handleClick(this);" onmouseover="handleMouseOver(this);" onmouseout="handleMouseOut(this);">', "\n";
心头的小情儿 2025-01-14 23:55:45
echo "<tr class=\"normal\" onclick=\"this.className='normalselected'\" 
       onmouseover=\"if (!/normalselected/gi.test(this.className)) this.className='normalon'\" 
       onmouseout=\"if (!/normalselected/gi.test(this.className)) this.className='normal'\">\n";

尽管我会认真考虑使用CSS悬停和适当的事件侦听器。

echo "<tr class=\"normal\" onclick=\"this.className='normalselected'\" 
       onmouseover=\"if (!/normalselected/gi.test(this.className)) this.className='normalon'\" 
       onmouseout=\"if (!/normalselected/gi.test(this.className)) this.className='normal'\">\n";

Though I would seriously consider using CSS hover, and proper event listeners.

沉溺在你眼里的海 2025-01-14 23:55:45

即使我不同意你这样做的方式,只是为了回答你的问题:你正在删除 mouseout 事件上的 normalselected 类,这是正常的。 条件来防止这种情况,

if('normalon' == this.className)

您可以通过添加类似于mouseout 事件处理程序的

而且当您再次访问已经选定的行时,您可能希望防止添加 normalon 类..因此您需要添加类似于

if('normal' == this.className) 

onmouseover 属性的内容。但如果你打算坚持使用 javascript,你真的应该考虑使用函数而不是所有这些条件

even if I don't agree to the way you did this, just to answer your question: you are removing the normalselected class on the mouseout event, that's normal. you can prevent that just by adding a condition like

if('normalon' == this.className)

to your mouseout event handler

also you might want to prevent adding the normalon class when you come again over an already selected row.. so you would need to add something like

if('normal' == this.className) 

to your onmouseover attribute.. but you should really consider using a function instead of all those conditions if you plan to stick with javascript for this

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