简体   繁体   中英

jquery val(); function and ruby on rails

I have a javascript variable there is = some html i print out from a tabel in my server.

I use the variable in the Jquery function val(); but the problems is every time a person write some content in a field something with a " sign or a ' sign. the javascript get confused.

var message = '<%= raw(post.content) %>';

$("button").click(function() {
  $("#somediv").val(message);
});

This code "<%= raw(post.content) %>" is a ruby on rails code there get the content from the content field in my post table.

Any suggestions what i can do?

"<%= j post.content %>" did solve the problem, like "vee" write in the comment.

http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-escape_javascript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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