js单引号中的预编码字符串更改为双引号
pre-code String Change in js single quotes to double quotes
您好,我需要用双引号更改此字符串,但我不知道该怎么做
现在就像
"<iframe src='"+urlSrv+'&embedded=true'+ "' frameborder='0' scrolling='auto' width='100%' height='100%'></iframe>"
输出为
<iframe src='http://localhost:46030/Login/Appointment%20Booking/Home.aspx?clhid=717c043d-126f-4f57-910b-247a83d58801?embedded=true' frameborder='0' scrolling='auto' width='100%' height='1000'></iframe>
但我需要把它变成
<iframe src="http://localhost:46030/Login/Appointment%20Booking/Home.aspx?clhid=717c043d-126f-4f57-910b-247a83d58801&embedded=true" frameborder="0" scrolling="auto" width="100%" height="1000"></iframe>
下面的脚本我正在转换它
dvContSrvBtnCopy.className = "col-lg-2 col-md-2 col-sm-2 col-xs-2 padddiv";
dvContSrvBtnCopy.style.marginTop = "-2rem";
var pre = document.createElement('pre');
pre.className = 'precode';
var code = document.createElement('code');
if (type == "ServiceCatg") {
code.id = "txtFrameSrv_" + i;
code.innerHTML = '<iframe src="'+urlSrv+'&embedded=true'+ '" frameborder="0" scrolling="auto" width="100%" height="1000" ></iframe>';
}
pre.appendChild(code);
dvContSrv.appendChild(pre);
var btnCopy = document.createElement("button");
btnCopy.className = 'btnCOPYOnlineBkDynamic';
btnCopy.type = "button";
if (type == "ServiceCatg") {
btnCopy.id = "btnCopySrv_" + i;
btnCopy.setAttribute('onclick', "StaffSrvCrclCopy('" + btnCopy.id + "','ServiceCatg',true);");
}
var spnCopy = document.createElement("span");
spnCopy.className = 'copyDOOnlineBk';
btnCopy.appendChild(spnCopy);
dvContSrvBtnCopy.appendChild(btnCopy);
这是否解决了您的问题?
'<iframe src="' + urlSrv + '" frameborder="0" scrolling="auto" width="100%" height="1000"></iframe>'
我发现通过用单引号将 HTML 嵌入 Javascript 最容易阅读,您可以继续像往常一样在 HTML 中使用双引号。
如果需要在html中使用单引号,可以这样转义:
\'
如果你想要双重代码,你可以使用转义符号。
"<iframe src=\"" + urlSrv + "\"&embedded=\"true\" frameborder=\"0\" scrolling=\"auto\" width=\"100%\" height=\"100%\"></iframe>"
如果您已经有了单引号字符串并想用双引号替换单引号,您可以使用 string.replace()
:
var s2 = s.replace(/'/g, "\"");
至于一个完整的例子:你有这两个 pre
-标签:
<pre id="content1"></pre>
<pre id="content2"></pre>
然后下面的Javascript将第一个填充单引号字符串,第二个填充双引号字符串:
var urlSrv = "http://localhost/";
var s = "<iframe src='"+urlSrv+'&embedded=true'+ "' frameborder='0' scrolling='auto' width='100%' height='100%'></iframe>";
var el = document.getElementById("content1");
el.innerHTML = s;
// Here we replace all the single quotes with double qutes
var s2 = s.replace(/'/g, "\"");
var el2 = document.getElementById("content2");
el2.innerHTML = s2;
您好,我需要用双引号更改此字符串,但我不知道该怎么做
现在就像
"<iframe src='"+urlSrv+'&embedded=true'+ "' frameborder='0' scrolling='auto' width='100%' height='100%'></iframe>"
输出为
<iframe src='http://localhost:46030/Login/Appointment%20Booking/Home.aspx?clhid=717c043d-126f-4f57-910b-247a83d58801?embedded=true' frameborder='0' scrolling='auto' width='100%' height='1000'></iframe>
但我需要把它变成
<iframe src="http://localhost:46030/Login/Appointment%20Booking/Home.aspx?clhid=717c043d-126f-4f57-910b-247a83d58801&embedded=true" frameborder="0" scrolling="auto" width="100%" height="1000"></iframe>
下面的脚本我正在转换它
dvContSrvBtnCopy.className = "col-lg-2 col-md-2 col-sm-2 col-xs-2 padddiv";
dvContSrvBtnCopy.style.marginTop = "-2rem";
var pre = document.createElement('pre');
pre.className = 'precode';
var code = document.createElement('code');
if (type == "ServiceCatg") {
code.id = "txtFrameSrv_" + i;
code.innerHTML = '<iframe src="'+urlSrv+'&embedded=true'+ '" frameborder="0" scrolling="auto" width="100%" height="1000" ></iframe>';
}
pre.appendChild(code);
dvContSrv.appendChild(pre);
var btnCopy = document.createElement("button");
btnCopy.className = 'btnCOPYOnlineBkDynamic';
btnCopy.type = "button";
if (type == "ServiceCatg") {
btnCopy.id = "btnCopySrv_" + i;
btnCopy.setAttribute('onclick', "StaffSrvCrclCopy('" + btnCopy.id + "','ServiceCatg',true);");
}
var spnCopy = document.createElement("span");
spnCopy.className = 'copyDOOnlineBk';
btnCopy.appendChild(spnCopy);
dvContSrvBtnCopy.appendChild(btnCopy);
这是否解决了您的问题?
'<iframe src="' + urlSrv + '" frameborder="0" scrolling="auto" width="100%" height="1000"></iframe>'
我发现通过用单引号将 HTML 嵌入 Javascript 最容易阅读,您可以继续像往常一样在 HTML 中使用双引号。
如果需要在html中使用单引号,可以这样转义:
\'
如果你想要双重代码,你可以使用转义符号。
"<iframe src=\"" + urlSrv + "\"&embedded=\"true\" frameborder=\"0\" scrolling=\"auto\" width=\"100%\" height=\"100%\"></iframe>"
如果您已经有了单引号字符串并想用双引号替换单引号,您可以使用 string.replace()
:
var s2 = s.replace(/'/g, "\"");
至于一个完整的例子:你有这两个 pre
-标签:
<pre id="content1"></pre>
<pre id="content2"></pre>
然后下面的Javascript将第一个填充单引号字符串,第二个填充双引号字符串:
var urlSrv = "http://localhost/";
var s = "<iframe src='"+urlSrv+'&embedded=true'+ "' frameborder='0' scrolling='auto' width='100%' height='100%'></iframe>";
var el = document.getElementById("content1");
el.innerHTML = s;
// Here we replace all the single quotes with double qutes
var s2 = s.replace(/'/g, "\"");
var el2 = document.getElementById("content2");
el2.innerHTML = s2;