我正在嘗試使用動態填充的字符串附加到我的html文件來開發工具提示。我設法用一個警告框打印出字符串,但是當我嘗試將它用作工具提示時,似乎沒有出現,即使該字符串被附加到html文件但未顯示。找到我的代碼如下 HMTL:動態工具提示
function handler(ev){
\t var counter = 0;
\t var target = $(ev.target);
\t var id= target.attr('id');
\t function check(ev){
var moteJson = [{"mote_id":101, "location": "qwert", "platform":"x1"}, {"mote_id":102, "location": "qwert", "platform":"x2"}, {"mote_id":103, "location": "qwert", "platform":"x3"}];
\t \t if (counter<1){
\t \t \t var target = $(ev.target);
\t \t \t var id= target.attr('id');
\t \t \t if (target.is(".button")) {
\t \t \t \t for (i=0; i<moteJson.length; i++){
\t \t \t \t \t if (moteJson[i].mote_id == id){
\t \t \t \t \t \t var display = "<div class = 'info'><p>Mote_id: " +moteJson[i].mote_id + "\nLocation: " + moteJson[i].location + "\nPlatform: " + moteJson[i].platform + "</p></div>";
\t \t \t \t \t \t $("#"+id).html(display);
\t \t \t \t \t \t
\t \t \t \t \t }
\t \t \t \t }
\t \t \t }
\t \t }
\t counter++;
\t }
\t $(".button").mouseleave(check);
}
.button.info{
\t visibility: hidden;
width: 120px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 1s;
}
.button.info::after {
\t content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
.button:hover .info {
\t visibility: visible;
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#GFDisplay"><input type="button" value="104" name="104" id="104" class="button" onmouseover="handler(this)" style="position: absolute; left: 40px; top: 40px; background-color: green;"></a>
你的JS有錯誤。確保你給我們一個工作[mcve]''未捕獲的ReferenceError:moteJson沒有定義'' –
現在應該修復 –