簡體   English   中英

第二次單擊時,jQuery中沒有函數錯誤

[英]not a function error in jquery when click on second time

我在wordpress插件中遇到問題。 我已經制作了位於該位置的圖像區域地圖。

http://singhalcompetitionclasses.com/newspaper/

在此,我創建了兩個區域圖。

當我第一次在任何區域地圖上單擊時,它將顯示彈出窗口

但是當我再次單擊任何區域地圖時,它將在控制台中顯示錯誤

hello is not a function

我使用的代碼如下:

<script>
function hello(id){ 
        var path = "<?php echo $path; ?>";
        alert(id);
        var path = path+id+'/'+id+'.jpg';
        image = "<img src='"+path+"' id='hello'>";
        //alert(image);
        jQuery("#hidden").html(image);
         var newwindow = window.open(jQuery(this).prop('href'), '', 'height=800,width=800');
       // if (window.focus) {
            newwindow.focus();
            newwindow.document.write( jQuery("#hidden").html() );
        //}
        return false;
    }
</script>

<div style="width: 900px; overflow: scroll; float: left;">
<img src="<?php echo $img_src;?>" id="photo" style="width: 850px;" usemap="#planetmap" />
</div>
<map name="planetmap">
<?php
$sql = mysql_query("select * from epaper");
while($row = mysql_fetch_array($sql)){
    $xx = $row['file_id'];
    echo '<area shape="rect" style="cursor:pointer;" coords="'.$row['x1'].','.$row['y1'].','.$row['x2'].','.$row['y2'].'" target="_blank" onclick="return hello('.$xx.');" alt="Sun" onmouseover="borderit(this,"black")" onmouseout="borderit(this,"white")">';
}
?>
<div id="hidden" style="display:none;">

</div>
</map>

請大家幫我解決問題

I have checked the coded there is string error you can use below code:
I hope this is fine for you:-

while($row = mysql_fetch_array($sql)){
    $xx = $row['file_id'];
    ?>
        <area shape="rect" style="cursor:pointer;" coords="<?php echo $row['x1'].','.$row['y1'].','.$row['x2'].','.$row['y2']; ?>" target="_blank" onclick="return hello('<?php echo $xx; ?>');" alt="Sun" onmouseover="borderit(this,'black')" onmouseout="borderit(this,'white')">
    <?php   }  ?>

OR

echo '<area shape="rect" style="cursor:pointer;" coords="'.$row['x1'].','.$row['y1'].','.$row['x2'].','.$row['y2'].'" target="_blank" onclick="return hello('.$xx.');" alt="Sun" onmouseover="borderit(this,\'black\')" onmouseout="borderit(this,\'white\')">'; 

您的函數名稱用作其中的html元素的ID。 它會混淆瀏覽器。

更改此行的ID:

image = "<img src='"+path+"' id='hello'>";

到(示例):

image = "<img src='"+path+"' id='other_id'>";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM