小编Cod*_*ter的帖子

有什么简单的方法可以在那个 onload 中定位一个带有 onload 的元素?

假设你想用 JS 将一个元素变成蓝色,像这样:

<p onload="this.style.color = 'blue'">Boy, I sure do wish I was blue</p>
Run Code Online (Sandbox Code Playgroud)

上面的行不起作用,因为this目标是该上下文中的 window 对象。您可以使用 ID,但我认为有更好的方法。

那么,就像标题所说的那样,有没有什么简单的方法可以在那个 onload 中定位一个带有 onload 的元素?请注意,当页面中有多个具有该onload属性的元素时,这种解决方案必须有效。

html javascript onload targeting

5
推荐指数
1
解决办法
1252
查看次数

如何让body取一个等同于style ="background-color:returnBlue()"的样式属性,其中returnBlue()返回"blue"?

<html>
  <body style="background-color: returnBlue()">
    <em>Boy, I sure do wish I existed on something that was blue.</em>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

风格不会使身体变蓝

function returnBlue()
{
   return 'blue';
}
Run Code Online (Sandbox Code Playgroud)

如何使returnBlue()函数运行并返回属性?谢谢!

html javascript css return attr

1
推荐指数
1
解决办法
59
查看次数

Pascal整数到字符串转换

是否有内置函数将整数转换为Free Pascal中的字符串,如返回整数输入的字符串对象?我已经为谷歌和文档提供了2个小时的能力,并且只找到了虚假的希望和失望.在Windows 10上使用Lazarus 1.4.4.

另外,为什么帕斯卡如此复杂/加重?有大量的版本,IDE,应用程序支持与非应用程序支持,文档最好是平庸(至少对于Free Pascal,尽管Delphi看起来也不是很好看).它遍布整个地方,就像一对巨大的纠结耳塞.

谢谢!

pascal freepascal lazarus

0
推荐指数
2
解决办法
6462
查看次数

C++不截断双打?

我的代码:

运行以下代码的结果:

#include <cstdio>

//i define printBits elsewhere but that's not relevant to my question
void printBits(const float f);
void printBits(const double f);

int main(int argc, char **argv) {
  float f=4.2;
  double d=4.2;
  printf("float: %20.20f\n",f);
  printBits(f);
  printf("double: %50.50f\n",d);
  printBits(d);

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

方法是:

float: 4.19999980926513671875
0    10000001 00001100110011001100110

double: 4.20000000000000017763568394002504646778106689453125
0 10000000001 0000110011001100110011001100110011001100110011001101
Run Code Online (Sandbox Code Playgroud)

注意我是如何设置都fd4.2,但浮点值略小于4.2和双值略微超过4.2.我理解为什么浮点值小于4.2; 4.2值被截断为小于4.2的值~2 ^ -21.不过,我不明白为什么双值略微大于比4.2.我认为float和double值只会被截断,但似乎双值是向上而不是向下.

一般来说,浮点数和双精度数是否为最接近的可表示值?浮动和双打不同吗?我试过搜索这个,但找不到任何相关的东西.

c++ floating-point precision double floating-accuracy

0
推荐指数
1
解决办法
55
查看次数