这是阵列
var copyText= [
'this is the first line',
'Simply put, the second line',
'impressed by the third line.'
];
Run Code Online (Sandbox Code Playgroud)
这些不起作用......
$("#thisbutton").click(function () {
$("#thetext").innerHTML("meow meow");
});
Run Code Online (Sandbox Code Playgroud)
要么
$("#thisbutton").click(function () {
$("#thetext").innerHTML(copyText[1]);
});
Run Code Online (Sandbox Code Playgroud)
要么
$("#thisbutton").click(function () {
$("#thetext").text(copyText[1]);
});
$("#thisbutton").click(function () {
$("#thetext").html(copyText[1]);
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么?THKS.
PHP/CSS在字符串中查找单词,更改其颜色以供显示.有问题,找不到解决方案,有什么建议吗?谢谢.
<pre>
<?php
$str="Try to realize the truth... there is no spoon."; // spoon can be anywhere in string
$array = explode(" ", $str);
for($i=0;$i < count($array);$i++)
{
if ($array[$i] == "spoon") {
?><span style="color:red;"><?php echo echo $array[$i]." "; ?></span>
<?php
} else {
echo $array[$i]." ";
}
} ?>
</pre
Run Code Online (Sandbox Code Playgroud) 在Javascript中,我正在寻找转换的最佳方式:
var data1 = [["ff",4],["gg",3],["dd",2],["hh",1]];
Run Code Online (Sandbox Code Playgroud)
至:
var data2 = [
{word: "ff", frequency: 4},
{word: "gg", frequency: 3},
{word: "dd", frequency: 2},
{word: "hh", frequency: 1}
]
Run Code Online (Sandbox Code Playgroud)
首先会创建一个对象:
var data2 = {};
Run Code Online (Sandbox Code Playgroud)
然后通过For循环运行它以使用data1内容填充它.
for (i = 0; i < data1.length; i++) {
data2[word] = data1[i][0];
data2[frequency] = data1[i][1];
}
Run Code Online (Sandbox Code Playgroud)