How do I escape characters in a Jquery string
I have this following string that I am trying to populate a textarea with how do I es开发者_如何学编程cape the " and ' in order for the text to show up in the box? Here is the code below:
$(document).ready(function(){
$('#queryarea').html("mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')")");
});
$(document).ready(function(){
$('#queryarea').html("mysql_query(\"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')\")");
});
You can escape them by doing \"
Use \
to escape strings
$('#queryarea').html("mysql_query(\"INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')\")");
I did it this way instead:
$(document).ready(function(){
var mysql1 = "mysql_query(\"";
var mysql2 = "INSERT INTO Persons (FirstName, LastName, Age) VALUES (\'Peter\', \'Griffin\', \'35\')";
var mysql3 = "\"";
$('#queryarea').html(mysql1+mysql2+mysql3);
});
Thanks for the help.
精彩评论