我有一个<div>
元素,点击后会更新页面上的内容。如何添加此JS代码的链接?我做了一个基本上我的问题的JSFiddle。基本上""
结束得太快,所以必须有一个像%20
这样的角色去做我的肮脏工作。有可能吗?
$("#content").html("<a herf="http://www.google.com">google.com</a>");
答案 0 :(得分:4)
在双引号内使用单引号:
$("#content").html("<a href='http://www.google.com'>google.com</a>"); } ); });
此外,它不是herf
而是href
答案 1 :(得分:1)
有两种方法可以处理这个
使用单引号和双引号的组合,例如"'"
或'"'
$("#content").html("<a href='http://www.google.com'>google.com</a>");
或使用此"\""
或'\''
$("#content").html("<a href=\"http://www.google.com\">google.com</a>");