简体   繁体   中英

How can I make a javascript variable and use it with jQuery

How can you make a javascript variable and use it with jQuery?

I use the following command unsuccessfully in trying to get the POST data out of the var answer. I can access the variable in HTML by $_POST['answer'].

var answer = $('#answer').val();

I use this variable in this code

jQuery('div.answer_' + $answer + ' a.delete_answer')
           .live('click', function(){

You should be doing:

var $answer = $('#answer').val();

You have a '$' in your selector. You would have to remove the '$' in the selector if you don't want a $ in your variable.

See this:

The $ dollar sign

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