2014-01-08 62 views
0

爲什麼這段代碼無法運行?我簡直不能理解,我花了幾個小時,我仍然無法找到我的錯誤,它適用於jsfiddle,從不與我和我的網站一起工作。上的jsfiddle jsfiddleAnoying,它可以在jsfiddle上工作,而不是在我的網站上

我的代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

<title>My site</title> 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

<script type="text/javascript"> 
// mouse-on examples 
$('#mouseon-examples div').data('powertipjq', $([ 
    '<p><b>Here is some content</b></p>', 
    '<p><a href="http://stevenbenner.com/">Maybe a link</a></p>', 
    '<p><code>{ placement: \'e\', mouseOnToPopup: true }</code></p>' 
    ].join('\n'))); 
$('#mouseon-examples div').powerTip({ 
    placement: 'e', 
    mouseOnToPopup: true 
}); 


</script> 
</head> 

<body> 

<div id="mouseon-examples">dfgdg</div> 

</body> 
</html> 

<style type="text/css"> 
#mouseon-examples div { 
    background-color: #EEE; 
    text-align: center; 
    width: 200px; 
    padding: 40px; 
} 

</style> 
+1

請把一個更好的問題標題...也你能澄清一下「不起作用」的意思嗎? – aug

+0

您是否在您的網站上看到控制檯錯誤? – Brad

+4

您需要在DOM準備好後運行您的代碼。 '$(function(){//你的代碼});'。 –

回答

1

必須在您的jsfiddle啓用了文件的onLoad選項(編輯:其實你這樣做),

如果是這樣,你需要把它放在你的代碼:

$(function(){ 
$('#mouseon-examples div').data('powertipjq', $([ 
    '<p><b>Here is some content</b></p>', 
    '<p><a href="http://stevenbenner.com/">Maybe a link</a></p>', 
    '<p><code>{ placement: \'e\', mouseOnToPopup: true }</code></p>' 
    ].join('\n'))); 
$('#mouseon-examples div').powerTip({ 
    placement: 'e', 
    mouseOnToPopup: true 
}); 
}) 

CNC中

好像喲ü忘了CSS,將其添加到HTML <head>

<link rel="stylesheet" type="text/css" href="http://stevenbenner.github.com/jquery-powertip/styles/jquery.powertip.css">

CNC中

整個代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 

    <title>My site</title> 

    <link rel="stylesheet" type="text/css" href="http://stevenbenner.github.com/jquery-powertip/styles/jquery.powertip.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

    <script type="text/javascript"> 
    // mouse-on examples 
    $(function(){ 
     $('#mouseon-examples div').data('powertipjq', $([ 
      '<p><b>Here is some content</b></p>', 
      '<p><a href="http://stevenbenner.com/">Maybe a link</a></p>', 
      '<p><code>{ placement: \'e\', mouseOnToPopup: true }</code></p>' 
      ].join('\n'))); 
     $('#mouseon-examples div').powerTip({ 
      placement: 'e', 
      mouseOnToPopup: true 
     }); 
     }) 


    </script> 
<style type="text/css"> 
    #mouseon-examples div { 
     background-color: #EEE; 
     text-align: center; 
     width: 200px; 
     padding: 40px; 
    } 

    </style> 
    </head> 

    <body> 

    <div id="mouseon-examples">dfgdg</div> 

    </body> 
    </html> 
+0

仍然無法正常工作。它只顯示純文本,不行動。 – user3174677

+0

這是插件我試着實現http://jsfiddle.net/stevenbenner/2baqv/ – user3174677

+0

你好,請檢查我的編輯 –

0
$(document).ready(function(){ 
    $('#mouseon-examples div').data('powertipjq', $([ 
     '<p><b>Here is some content</b></p>', 
     '<p><a href="http://stevenbenner.com/">Maybe a link</a></p>', 
     '<p><code>{ placement: \'e\', mouseOnToPopup: true }</code></p>' 
     ].join('\n'))); 
    $('#mouseon-examples div').powerTip({ 
     placement: 'e', 
     mouseOnToPopup: true 
    }); 
}); 
相關問題