I was going through some of StackOverflow's client side code and I ran across this block of JavaScript in the source-code of https://stackoverflow.com/questions/ask
:
if ($answerCheckbox.is(':checked') || 0 > 0) {
$answerCheckbox.attr('checked', true);
$('#question-only-section').hide();
StackExchange.using("editor", function () {
setTimeout(function () { showAnswerSection(true) }, 2);
});
}
Why wouldn't you use false
instead?
You're assuming the code is all natively written Javascript. It isn't uncommon to see some server-generated script which references elements via some programmatic identifier which resolves like this at runtime, which admittedly looks a little peculiar.
它是生成的代码(不在.js文件中),所以显然这两个值中的一个并不总是0而是服务器端变量。
There is no reason for it... but until you know the server side code, you can't know for sure.
Let's say (PHP) you had a variable $x=1
and could also be $x=0
depending on the scenario.
if ($answerCheckbox.is(':checked') || <?php echo $x;?> > 0) {
That code makes perfect sense....
Because that line probably comes from php, like so:
if ($answerCheckbox.is(':checked') || <?php echo $tot; ?> > 0) {
I know because in some situations I had to write code like that.
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.