[英]Insert string inside the head tag
var c = <head></head><body></body>
i want to insert base tag between head tag. 我想在标签之间插入基本标签。 The above head tag is not in html form its inside the variable, now i want to modify this c variable like shown below
上面的head标签不是以html形式存在于变量内部,现在我想修改此c变量,如下所示
<head><base target="_blank"/></head><body></body>
Anyone knows..... 有谁知道.....
You can use .append()
: 您可以使用
.append()
:
$('head').append('<base target="_blank"/>');
to append at first position,use .prepend()
: 使用
.prepend()
在第一位置追加:
$('head').prepend('<base target="_blank"/>');
Since what you proposed isn't valid javascript or HTML, I'm assuming what you really meant was that you have a javascript variable c
that is a javascript string like this: 由于您提出的不是有效的javascript或HTML,因此我假设您真正的意思是您有一个javascript变量
c
,它是一个像这样的javascript字符串:
var c = '<head></head><body></body>';
and you want to change it to this: 而您想要将其更改为:
var c = '<head><base target="_blank"/></head><body></body>';
If that is what you meant, you could do that like this: 如果这就是您的意思,则可以这样操作:
c = c.replace('<head>', '<head><base target="_blank"/>');
Working demo: http://jsfiddle.net/jfriend00/4p6wf/ 工作演示: http : //jsfiddle.net/jfriend00/4p6wf/
If you meant something different, then please clarify by editing your question. 如果您的意思不同,请通过编辑问题进行澄清。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.