Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.open在字符串内部不工作_Javascript - Fatal编程技术网

Javascript window.open在字符串内部不工作

Javascript window.open在字符串内部不工作,javascript,Javascript,我想使用window.open方法打开窗口,但我想在字符串函数中使用此函数。我已经写了一些代码,但它不工作 <head> <script type="text/javascript" src="../jquery-1.8.3.js"></script> <script type="text/javascript"> $(function(){ var str= '<a href="javascript:void(0)" onclick="wi

我想使用window.open方法打开窗口,但我想在字符串函数中使用此函数。我已经写了一些代码,但它不工作

<head>
<script type="text/javascript" src="../jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
var str= '<a href="javascript:void(0)" onclick="window.open("http://www.google.com","mywin","height=1000, width=500")">google</a>'
$('body').append(str)
})</script>
</head>
<body>
</body>

$(函数(){
var str=''
$('body').append(str)
})

这是因为你在引号中加引号(
“你好,世界!”
)。您需要使用反斜杠(
\
)。更改:

致:


这是因为你在引号中加引号(
“你好,世界!””
)。您需要使用反斜杠(
\
)。更改:

致:


引号不匹配。。添加反斜杠(/)

var str=''

引号不匹配。。添加反斜杠(/)

var str=''

您应该将转义字符添加到“字符串内…”

var str= '<a href="javascript:void(0)" onclick="window.open(\"http://www.google.com\",\"mywin\","height=1000, width=500\")">google</a>';
var-str='';

您应该将转义字符添加到“字符串内…”

var str= '<a href="javascript:void(0)" onclick="window.open(\"http://www.google.com\",\"mywin\","height=1000, width=500\")">google</a>';
var-str='';

问题是您在另一个
中使用了
,因此需要对该
\
使用转义字符

以下是更新后的代码-

<head>
<script type="text/javascript" src="../jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
var str= '<a href="javascript:void(0)" onclick="window.open(\"http://www.google.com\",\"mywin\",\"height=1000, width=500\")">google</a>'
$('body').append(str)
})</script>
</head>
<body>
</body>

$(函数(){
var str=''
$('body').append(str)
})

问题是您在另一个
中使用了
,因此需要对该
\
使用转义字符

以下是更新后的代码-

<head>
<script type="text/javascript" src="../jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
var str= '<a href="javascript:void(0)" onclick="window.open(\"http://www.google.com\",\"mywin\",\"height=1000, width=500\")">google</a>'
$('body').append(str)
})</script>
</head>
<body>
</body>

$(函数(){
var str=''
$('body').append(str)
})
您需要使用
\'

$(function(){
    var str= '<a href="javascript:void(0)" onclick="window.open(\'http://www.google.com\',\'mywin\',\'height=1000, width=500\')">google</a>'
    $('body').append(str)
})
$(函数(){
var str=''
$('body').append(str)
})
演示:

您需要使用
\'

$(function(){
    var str= '<a href="javascript:void(0)" onclick="window.open(\'http://www.google.com\',\'mywin\',\'height=1000, width=500\')">google</a>'
    $('body').append(str)
})
$(函数(){
var str=''
$('body').append(str)
})

演示:

您可以使用其他功能

var clickFunc=function () {window.open("http://www.google.com","mywin","height=1000, width=500")};
var str= '<a href="javascript:void(0)" onclick="clickFunc()">google</a>';
var clickFunc=function(){window.open(“http://www.google.com“,”mywin“,”高度=1000,宽度=500“)};
var-str='';

您可以使用其他功能

var clickFunc=function () {window.open("http://www.google.com","mywin","height=1000, width=500")};
var str= '<a href="javascript:void(0)" onclick="clickFunc()">google</a>';
var clickFunc=function(){window.open(“http://www.google.com“,”mywin“,”高度=1000,宽度=500“)};
var-str='';
var str=”“;
var str=”“;

在双引号内调用函数时,必须使用单引号。你可以这样做:

onclick="window.open('http://www.google.com')"

在双引号内调用函数时,必须使用单引号。你可以这样做:

onclick="window.open('http://www.google.com')"

欢迎来到StackOverflow。你能解释一下错误到底在哪里,以及你做了什么来修复它吗?谢谢。欢迎来到StackOverflow。你能解释一下错误到底在哪里,以及你做了什么来修复它吗?谢谢