开发者

Sending remember me checkbox in dataString [closed]

开发者 https://www.devze.com 2023-03-12 20:42 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, over开发者_高级运维ly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, over开发者_高级运维ly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消