我正在尝试建立一个计时器.请比较两种情况(第一种情况有效,而不是第二种情况):
问题是什么?
尝试做一些更复杂的事情,但我似乎不理解向元素添加样式的基础知识?我究竟做错了什么?
这是工作jsfiddle http://jsfiddle.net/akshaytyagi/SD66b/的链接
以下是我试图在我的网站上运行的代码(与jsFiddle相同)
我试过两台电脑.我究竟做错了什么?
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var tips = [
"creative",
"innovative",
"awesome",
"amazing",
"social"
];
setInterval(function() {
var i = Math.round((Math.random()) * tips.length);
if (i == tips.length)--i;
$('#tip').slideUp(500, function() {
var $this = $(this);
$this.html(tips[i]);
$this.toggleClass('first second');
$this.slideDown(500);
});
}, 3 *1000);
});
</script>
</head>
<body>
<div style=" background-position:center; background-repeat:no-repeat; background-color:#c84d5f; height:500px">
<div class="thousand">
<div style="font-size:72px; font-family:Museo; padding-top:100px; padding-left:auto; padding-right:auto; color:#FFF;">The <span id="tip">creative</span><br />brand.
</div>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 这是非常基本的,但它不起作用.我知道我必须遗漏一些非常明显的东西.
这是小提琴.
<input type="button" onclick='clicked();' value='Click Me!'></input>
function clicked() {
alert('test');
}
Run Code Online (Sandbox Code Playgroud) 好的,所以我有一个代码,根据下拉选择显示不同的形式
这里是小提琴 ..
好吧,它总是给我Test1,这意味着它没有改变div显示,它在JSFiddle上工作,但不在网页上..这里是我的网页标记
<html>
<body>
<style>
.hidden {
display: none;
}
</style>
<script type='text/javascript'>
document.getElementById('options').onchange = function() {
var i = 1;
var myDiv = document.getElementById(i);
while(myDiv) {
myDiv.style.display = 'none';
myDiv = document.getElementById(++i);
}
document.getElementById(this.value).style.display = 'block';
};
</script>
<select name="options" id="options">
<option value="1"> Display </option>
<option value="2">Wka</option>
</select>
<div id="1" class="hidden" style="display: block">Test 1</div>
<div id="2" class="hidden">Test 2</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我不知道为什么我的代码会停止工作,如果我在上一个函数中添加if语句var checkAnswer = function().如果我删除该声明,代码将再次正常工作.有什么问题呢?这有点奇怪,我不明白.
Array.prototype.random = function(length) {
return this[Math.floor(Math.random() * length)];
};
var country = [{
name: "romaniei",
capital: "bucuresti"
}, {
name: "bulgariei",
capital: "sofia"
}],
questions = [
"What is the capital of ",
" is the capital of what country?"
]
document.querySelector('input').onclick = function() {
var q,
chosen_country = country.random(country.length),
chosen_question = questions.random(questions.length);
if (chosen_question == questions[0]) {
q = chosen_question + chosen_country.name + "?";
} else if (chosen_question == questions[1]) {
q = …Run Code Online (Sandbox Code Playgroud)我是JavaScript的新手,我有一个小问题.
我创建了这个JSFiddle:https://jsfiddle.net/AndreaNobili/1up938xf/
我只定义了执行简单求和(无HTML)的JavaScript函数,并通过警报将结果显示在弹出窗口中
var add = function(x, y) {
z = z + y;
return z;
}
var sum = add(2, 3);
alert(sum);
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试运行这个测试应用程序时,我看不到任何东西.为什么?我错过了什么?
使用JSFiddle初学者的一点......尝试在我的代码中重新创建一个问题.不确定如何包含正确的参考.对于我使用的代码:
<link href="/jquery-ui-1.10.3.custom/css/start/jquery-ui-1.10.3.custom.min.css" rel="stylesheet" type="text/css" />
<script src="/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是如何在JSFiddle中包含这些文件.似乎无法从下拉中找到它们?
再次感谢
也许我今天早上没有喝足够的咖啡但是这个看似简单的循环我得到了一个奇怪的错误:
http://jsfiddle.net/za2Lrduo/1/
var a;
for(a = 1; a <= 100; a++){
a = document.createElement('div');
a.style.width = '10px';
a.style.height = '10px';
a.style.background = 'red';
document.body.appendChild(a);
}
Run Code Online (Sandbox Code Playgroud) 我想要完成的是将所有页面的页脚放在正文内容之下.所有页面都有不同大小的正文内容.对我来说,具有挑战性的一点是只为所有页面保留一个CSS.
我尽力在这里展示css和HTML,但没有运气.相反,这是我的代码的JSFiddle:https://jsfiddle.net/zsrsd20m/
.container {
min-height:80%;
position:relative;
}
.titleText{
width:100%;
padding-top: 35px;
padding-bottom: 35px;
background-color: #127577;
color: white;
text-align: center;
}
.navBar{
padding-right: 20px;
float:left;
}
.mainText{
height:100%;
padding-left:220px;
padding-right:250px;
padding-bottom:0px;
font-size: 20px;
text-align: justify;
}
.footerText{
width:100%;
padding-top: 35px;
padding-top: 23px;
background-color: #127577;
color: white;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
.Container和用HTML制作的所有其他Div都是因为这个:http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
我想要它,即使身体内容太小,页脚总是停留在页面的底部.如果身体内容很大,同样适用.目前,当将主体内容的高度设置为100%时,即使内容很小并且不需要滚动条,它也会显示滚动条.当移除高度时,它会使页脚直接位于较小的主体内容之下,这是一半好但不在页面的底部,所以它看起来很可怕.
问题截图:https: //imgur.com/a/x16RC