简体   繁体   English

单击时将字体更改为粗体-HTML PHP

[英]changing the font to bold when clicked - HTML PHP

I have a list on my left menu on site like FAQ topics, and when click on it on the right side different text from MySQL db showing onclick. 我在网站左侧菜单中有一个列表,如FAQ主题,当在右侧单击时,与MySQL数据库不同的文本显示onclick。

When a list item is clicked on I want to change that items font setting to bold so that the user gets a visual indicator that it's been selected and that user know he is on specific FAQ topic. 单击一个列表项时,我想将该项目的字体设置更改为粗体,以便用户可以直观地看到它已被选中,并且该用户知道他在特定的FAQ主题上。 Is this possible? 这可能吗?

You can is in code already have there onmousein and onmouseout effect done correctly there: 您可以在代码中已经在那里正确完成onmousein和onmouseout效果的地方:

<div class="boxHelpItem">
<?PHP

//Query
$result = mysql_query("SELECT * FROM faq_topics ORDER BY number ASC");
while ($row = mysql_fetch_array($result))
{
    $result1 = mysql_query("SELECT * FROM faq_questions WHERE topicid='$row[id]' ORDER BY number ASC");

    echo '<div style="height:15px; padding-top:5px; font-size:13px;">' . $row['title'] . '</div>';
    echo '<ul style=" padding-left:10px;">';
    while ($row1 = mysql_fetch_array($result1))
    {
        echo '<li style="color:#404040; font-size:12px;" onclick="faqGet(\'' . $row1['id'] . '\');" onmouseover="this.style.textDecoration = \'underline\';" onmouseout="this.style.textDecoration = \'\';">' . $row1['title'] . '</li>';
    }
    echo '</ul>';
}

?>
</div> 

You could use the onclick event... 您可以使用onclick事件...

onclick="faqGet(\'' . $row1['id'] . '\'); this.style.fontWeight='bold';"

Although you will also need to unset the other items, so you may want to move the logic out of the element into a function. 尽管您还需要取消其他项的设置,但是您可能需要将逻辑从元素中移出到函数中。 You could then loop over the list items and remove the styling, and then set the selected one. 然后,您可以遍历列表项并删除样式,然后设置选定的样式。

Also, you might want to read up a bit on removing your JavaScript from your HTML, it is quite easy to do and will make your HTML easier to maintain. 另外,您可能需要阅读一些有关从HTML中删除JavaScript的信息,这很容易做到,并且会使HTML易于维护。

My final point would be that if you made each FAQ a proper link, you could provide fallback behaviour for JavaScript fails, and also use CSS to style the current item... 我的最后一点是,如果您将每个FAQ设置为正确的链接,则可以提供JavaScript失败的后备行为,还可以使用CSS设置当前项目的样式...

a:focus { font-weight: bold; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM