如何在html上使用div标签中的jquery更改样式表?或者更改样式表的jquery代码是什么?
在javascript中,我们使用以下代码:
<script type="text/javascript">
function changeStyle() {
document.getElementById('stylesheet').href = 'design4.css';
}
</script>
Run Code Online (Sandbox Code Playgroud)
有jQuery的方式吗?
嗨,我有以下我试图运行的JavaScript代码.我的目标是掌握this
JavaScript中不同范围和不同类型的调用的含义.
如果你查看下面的代码:我有一个内部匿名函数,它被赋值给innerStuff
变量.在那个匿名函数中,这样this
指向window
对象而不是外部函数对象或其他任何东西.事件虽然它仍然可以访问函数的变量.
无论如何,我不确定,为什么会这样; 但是如果你看下面的代码,我会以后的this
形式传递that
给innerStuff
它,它可以正常运行并doofus
在控制台中打印带有属性的对象.
var someStuff = {
doofus:"whatever",
newF: function()
{
var that = this;
console.log(that);
var innerStuff = function(topThis){
console.log(topThis);
};
return innerStuff(that);
}
}
someStuff.newF();
Run Code Online (Sandbox Code Playgroud)
现在我只是改变了一点代码.而不是分配它innerStuff
,我只是通过调用它直接返回该函数,如下所示:
var someStuff = {
doofus:"whatever",
newF: function()
{
var that = this;
console.log(that);
return function(that){
console.log(that);
}();
}
}
someStuff.newF();
Run Code Online (Sandbox Code Playgroud)
这打印内部匿名函数未定义.是因为that
作为参数传递的内容与that
外部函数中定义的内容之间存在冲突吗?我认为参数会覆盖可见性.为什么价值不会保留?
这完全令人困惑.
另一方面,如果我没有通过that
,而只是使用它,因为可见性存在,结果是正确的和预期的.
我错过了什么?它是变量之间的冲突,存在于相同的范围内吗?有没有一个很好的理由,内部函数this
必然会受到window …
我有一个数组,我想使用MySQL数据库中的日期字段进行排序.
以下是news
在我的类中命名的数组示例:
[48] => Array
(
[id] => 14
[type] => 3
[updated] => 2010-04-17 13:54:42
)
[49] => Array
(
[id] => 15
[type] => 3
[updated] => 2010-04-17 13:57:21
)
Run Code Online (Sandbox Code Playgroud)
我想按updated
字段排序.
我有一些我已经开始的代码,但我不确定如何完成它并让它工作.
class ProcessClass {
// ....
function sortNews($x)
{
usort($this->news, array("ProcessClass", "cmp")); //correct sort type?
}
function cmp($a, $b)
{
// missing code
}
Run Code Online (Sandbox Code Playgroud)
谁能帮忙?
var array = new Array();
$.get('comics.txt', function(data) {
array = data.split(",");
for(var i = 0; i < array.length; i++)
{
var $page = array[i];
$.ajax({
url: $page,
success: function(data) {
alert(data);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
comics.txt是一个包含一些URL的文件,以逗号分隔.
在上面的代码中,$ .ajax调用不起作用; $ page是正确的URL,但它在上下文中不起作用.警报(数据)导致出现空白警告框.我需要帮助找出一种方法来从数组中的每个页面获取数据.
提前谢谢.
是否可以在GD生成的图像中包含外部图像(gif,jpg或png)?
我正在尝试做的是获取最新的wordpress博客文章(如5)并从中生成图像.我想在博客文章中包含标题和上传的图片.
我正在使用PHP解析一个大文本文件,有些行看起来像"äåòñêèåïåñíè",或"ääò",或者像这样的"åãîðëåò".有没有办法检查字符串中是否有超过三个这样的字符?
谢谢.
我有一个包含项目列表的简单页面.我允许用户对这些项目进行投票,但我只想让用户每次投票一次.项目.
我制作了一个jQuery脚本,为用户投票的项目添加了一个类:
if(!$(this).find(".item span").hasClass("voted")) {
$(".item").hover(function() {
$(this).find(".ratingbar").hide();
$(this).find(".votebar").show();
}, function() {
$(this).find(".votebar").hide();
$(this).find(".ratingbar").show();
});
};
Run Code Online (Sandbox Code Playgroud)
这是阻止用户再次对同一项目进行投票的脚本.
$(".votebutton").click(function() {
$("div#"+offerid).find(".item").addClass("voted");
});
Run Code Online (Sandbox Code Playgroud)
这不起作用.当悬停项目时,即使第二个脚本成功将"已投票"类添加到html,悬停功能仍会运行.
为什么会这样?
我正在尝试使用npm安装Johnny Five,但我一直在收到错误.这是我在终端窗口中得到的.
gyp ERR! build error
gyp ERR! stack Error: not found: make
gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:28)
gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:46:29)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:57:16
gyp ERR! stack at Object.oncomplete (fs.js:107:15)
gyp ERR! System Darwin 12.4.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/nevosegal/GitHub/node_modules/firmata/node_modules/serialport
gyp ERR! node -v v0.10.10
gyp ERR! node-gyp -v v0.9.6
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0
Run Code Online (Sandbox Code Playgroud)
以下是日志文件.任何人?
2793 error Error: …
Run Code Online (Sandbox Code Playgroud)