简体   繁体   English

使用javascript附加输入类型

[英]Appending Input type using javascript

I am appending HTML in javascript. 我在javascript中附加HTML。

var HTML = "<input type='image'  src='../../images/edit_btn.png' onclick='popadmin('http://www.example.com','station',585,971); return false;' style='border-width:0px;margin-top: 5px; margin-right: 0px'>";

but it generate this HTML 但它会生成此HTML

var HTML = <input type="image" src="../../images/edit_btn.png" onclick="popadmin(" http:="" www.example.com','station',585,971);="" return="" false;'="" style="border-width:0px;margin-top: 5px; margin-right: 0px">

Why this popadmin('http://www.example.com' change to http:="" www.example.com' ? how i can prevent it 为什么将此popadmin('http://www.example.com'更改为http:="" www.example.com' ?我如何防止它

那是因为您使用了错误的引号,所以请不要这样做:

var HTML = "<input type='image'  src='../../images/edit_btn.png' onclick=\"popadmin('http://www.example.com','station',585,971); return false;\" style='border-width:0px;margin-top: 5px; margin-right: 0px'>";

should use single quote. 应该使用单引号。

this is a example for "LI" is similar 这是一个与“ LI”相似的例子

function addLI(id, href, name){
var html = '<li><a id ="'+id+ '" href="' + href + '">' + name+ '</a></li>';
return html;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM