简体   繁体   English

鼠标悬停在输入上时出现的占位符

[英]Placeholder that appears when mouse is over the input

I am working on a Tic Tac Toe game.我正在开发井字游戏。 I have done everything but now I feel that there should be a feature that shows X or O when the cursor is over the respective input box.我已经做了所有事情,但现在我觉得应该有一个功能,当 cursor 在相应的输入框上方时显示 X 或 O。 The below code is my HTML.下面的代码是我的 HTML。 Just part of it but I think you will come to know how it works.只是其中的一部分,但我想你会知道它是如何工作的。

 <table style="border-collapse: collapse" cellpadding="0" cellspacing="0"> <tr> <th colspan=3> <h1>Tic Tac Toe</h1> </th> </tr> <tr> <th align="right"> <input class="cell" id="b1" type="text" onclick="myfunc_3(); myfunc();" readonly> </th> <th> <input class="cell" id="b2" type="text" onclick="myfunc_4(); myfunc();" readonly> </th> <th align="left"> <input class="cell" id="b3" type="text" onclick="myfunc_5(); myfunc();" readonly> </th> </tr> <tr> <th align="right"> <input class="cell" id="b4" type="text" onclick="myfunc_6(); myfunc();" readonly> </th> <th> <input class="cell" id="b5" type="text" onclick="myfunc_7(); myfunc();" readonly> </th> <th align="left"> <input class="cell" id="b6" type="text" onclick="myfunc_8(); myfunc();" readonly> </th> </tr> <tr> <th align="right"> <input class="cell" id="b7" type="text" onclick="myfunc_9(); myfunc();" readonly> </th> <th> <input class="cell" id="b8" type="text" onclick="myfunc_10(); myfunc();" readonly> </th> <th align="left"> <input class="cell" id="b9" type="text" onclick="myfunc_11(); myfunc();" readonly> </th> </tr> <tr> <th colspan="3"> <p id="print"></p> </th> </tr> <tr> <th id="restartBtn" colspan="3"> <button id="startGame" onclick="myfunc_2()">Restart Game!</button> </th> </tr> <tr> <th id="darkBtn" colspan="3"> <button id="darkMode" onclick="darkMode()">Turn On Dark Mode!</button> </th> </tr> </table>

Ok, so as you can see there are 9 input boxes which when clicked display X or O as per the turn of the player.好的,如您所见,有 9 个输入框,点击时会根据玩家的轮次显示 X 或 O。 enter image description here在此处输入图像描述

This is how it looks right now.这就是它现在的样子。 Now all I need is the Javascript.现在我只需要 Javascript。 I think that the code should change the placeholder so that when the cursor is over the cell It would show X or O as placeholder and when the cursor is not on top of cell the placeholder is not there anymore now I don't know how I would do it.我认为代码应该更改占位符,以便当 cursor 位于单元格上方时,它将显示 X 或 O 作为占位符,而当 cursor 不在单元格顶部时,占位符不再存在我不知道我是怎么做到的会做的。 I would love to see a solution.我很想看到一个解决方案。 Thank you so much!太感谢了!

It would be best to include the javascript that you already have, however from what I understand I think this is what you're looking for:最好包括您已经拥有的 javascript,但是据我了解,我认为这就是您正在寻找的:

You would want to add a onmouseover attribute that calls a javascript function that looks a bit like this:您可能想要添加一个 onmouseover 属性,该属性调用 javascript function 看起来有点像这样:

function showPlaceholder (id) {
    document.getElementById(id).placeholder = 'yourPlaceholder';
}

I do recommend that you show your entire javascript so we can help you better, as I also recommend instead of using a myfunc() every time with a different number to use a more descriptive title.我确实建议您展示您的整个 javascript,以便我们可以更好地帮助您,因为我还建议您不要每次都使用带有不同数字的myfunc()来使用更具描述性的标题。 Also, functions are made so you do not need to repeat the same lines of code every time so having 8 functions that do all the same thing kind of defeats the purpose.此外,函数是这样设计的,因此您不需要每次都重复相同的代码行,因此拥有 8 个执行所有相同操作的函数就无法达到目的。 It is better to use the element id as a parameter as I did in the example above.最好像我在上面的示例中那样使用元素id作为参数。

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

相关问题 当鼠标悬停在D3上时出现文本 - appears text when mouse is over D3 要覆盖的输入占位符 - input placeholder to be written over 鼠标结束时输入字段更新 - Input fields updates when mouse is over 释放鼠标时出现流星的“变化”值,而不是拖动输入滑块时出现? - Meteor `change` value appears when mouse released, not as input slider is dragged? JavaScript,在“鼠标悬停”上,当您尝试将鼠标移到它上面时,一个块出现并消失 - JavaScript, on "mouseover" a block appears and disappears when you try to move the mouse over it 是否可以创建一个工具提示,当鼠标悬停在其中的文本上时出现 <p> 标签? - Is it possible to create a tooltip that appears when the mouse is hovered over text inside <p> tags? Java-当鼠标悬停在按钮上方时,如何验证替代文本出现? - Java - How do I verify alt text appears when mouse hovers over a button? 仅当鼠标不在输入字段上时,JQUERY键入功能才会响应 - JQUERY keyup function response only when mouse is not over input field javascript如何在鼠标悬停在输入文本框上时显示文本? - javascript how to display text when mouse over input text box? 当鼠标悬停在输入文本框上时显示一些文本 - Displaying some text when mouse is over an input text box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM