开发者

Sending remember me checkbox in dataString [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜