javascript 带有onclick javascript弹出窗口的href

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17938852/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 10:11:10  来源:igfitidea点击:

href with onclick javascript pop-up

phpjavascripthtmlpopuphref

提问by Christian Burgos

i have this javascript:

我有这个 javascript:

<SCRIPT LANGUAGE="JavaScript">
<!-- 

// Generated at http://www.csgnetwork.com/puhtmlwincodegen.html 
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=400,left = 283,top = -16');");

}

// -->
</script>

i want to use an href with a javascript popup function but its not working. here is my code

我想使用带有 javascript 弹出功能的 href 但它不起作用。这是我的代码

 <?php
    echo "<a href = '#' onClick='javascript:popUp('editdelete.php?emoticon_text=$emoticon_text&id=$id')'><img src='update.png'></a>";
    ?>

but its not working

但它不工作

(the $emoticon_text and the $id will be passed to the pop up window using $_GET function.)

($emoticon_text 和 $id 将使用 $_GET 函数传递到弹出窗口。)

thanks

谢谢

回答by vee

You are mixing your quotes usage. Please try the following:

您正在混合使用引号。请尝试以下操作:

<a href = '#' onClick='javascript:popUp("editdelete.php?emoticon_text=$emoticon_text&id=$id")'><img src='update.png'></a>

Note the double quotes inside javascript:popUpinplace of single quote as you have in your question.

请注意javascript:popUp在您的问题中使用双引号代替单引号。

Update:

更新:

After OP's comment below:

在 OP 在下面发表评论之后:

<?php echo "<a href = '#' onClick='javascript:popUp(\'editdelete.php?emoticon_text=$emoticon_text&id=$id\')'??><img src='update.png'></a>"; ?>

回答by Goutam Pal

<a href = '#' onClick='javascript:popUp('editdelete.php?emoticon_text=$emoticon_text&id=$id')'><img src='update.png'></a>

should be

应该

<a href = '#' onClick="javascript:popUp('editdelete.php?emoticon_text=<?php echo $emoticon_text; ?>&id=<?php echo $id; ?>')"><img src='update.png'></a>