Sending remember me checkbox in dataString [closed]
I'm trying to find out if a checkbox in a form is checked and if it is then append a value to a string called dataString.
Is the following code appropriate?
var remember = $('#remember').attr('checked');
if (remember == True) {
dataString += &remember=True;
}
I will answer your question about adding to string, but as many of the comments have said, your question isn't clear as to whether you are asking about string operations or whether you are using that string properly in your submit/get/post/ajax call.
As of jQuery 1.6 you should be using .prop()
(link to API documentation) to check properties.
var dataString = '';
var rememberIsChecked = $('#remember').prop('checked');
//if var is boolean, no need to test equality to true
if (rememberIsChecked) {
dataString += '&remember=True'; //append to string
}
精彩评论