小编Sco*_*cus的帖子

切换CSS类对元素没有影响

我正在尝试创建一个基本的JavaScript下拉菜单.我正在切换一个名为"show"的类,它显示下拉内容.它不起作用 - 即使在应用类之后元素仍保持隐藏状态.

我想我在这里有一个错误,但我似乎无法找到它.救命!

		function drop() {
			document.getElementById('content').classList.toggle('show');
		}
Run Code Online (Sandbox Code Playgroud)
		.container {
			display: inline-block;
			position: relative;
		}
		.dropdown_btn {
			color: white;
			background-color: black;
			cursor: pointer;
			padding: 20px;
		}
		.dropdown_btn:hover, .dropdown_btn:focus {
			background-color: grey;
		}
		#content {
			display: none;
			position: absolute;
			background: grey;
			color: white;
			width: 160px;
		}
		.container a {
			text-decoration: none;
			display: block;
			padding: 10px;
			color: white;
		}
		.container a:hover {
			background-color: #f1f1f1
		}
		.show {
			display: block;
		}
Run Code Online (Sandbox Code Playgroud)
		<div class="container">
			<button class="dropdown_btn" onclick="drop()">Menu</button>
			<div id="content">
				<a href="">Link 1</a>
				<a …
Run Code Online (Sandbox Code Playgroud)

html javascript css

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

全局变量不在另一个文件中访问

我在header.php文件中声明了JavaScript中的全局变量,但是在footer.php文件中无法访问它

码:

header.php文件

<?php define('BASE_URL','https://example.com'); ?>
<!DOCTYPE html>
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascipt">
            var baseUrl = { url:"<?php echo BASE_URL; ?>" };
        </script>
        <meta charset="utf-8"/>
     </head>
     <body>
Run Code Online (Sandbox Code Playgroud)

的index.php

<?php
require_once("templates/header.php");
require_once("templates/footer.php");
Run Code Online (Sandbox Code Playgroud)

footer.php

<script type="text/javascript">
    alert(baseUrl.url);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在这里,我尝试访问footer.php文件中的baseUrl变量,但是我收到此错误

未捕获的ReferenceError:未定义baseUrl

寻求帮助!

javascript php

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

jQuery 淡入/淡出文本,然后淡入新文本

这是我第一次使用 jQuery,我正在为它参加在线课程,但从未在网站上使用过它。

我的目标是在主页上先让“你好”出现 2 秒,然后淡出并让“你的数字伙伴”淡入并永久停留。

我一直在这里尝试一些相关难题的想法,并且越来越接近。但我的结构似乎是错误的,因为:1) 两件事一开始都出现,然后“你好”开始消失,然后“你的伴侣被撞了”——我希望“你好”快速出现然后消失2)我希望“你的数字伙伴”一旦出现就永远不会消失

    jQuery(document).ready(function(){
        $(".hellothere").fadeOut(4500,function(){
            $(".partner").fadeIn(10000, function(){
                $(".partner").fadeOut(4500);
            });
        });
    });
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 class="hellothere"><span class="font-168856 font-444086" style="font-size: 65px; text-transform: uppercase;">Hello there.</span></h1>
    <h1 class="partner"><span class="font-168856 font-444086" style="font-size: 65px; text-transform: uppercase;">Your partner in digital.</span></h1>
Run Code Online (Sandbox Code Playgroud)

当我删除它时:

function(){
                $(".partner").fadeOut(4500);
Run Code Online (Sandbox Code Playgroud)

它打破了整个事情(试图让它停止消失)。

这里有什么提示吗?非常感谢。

html javascript css jquery

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

阻止用户从输入中删除特定文本

我在内部有一个可预测的文本:

div{
  padding: 10px;
  border: 1px solid black;
}
.some-class{
  background: yellow;
  padding: 0px 5px;
}
Run Code Online (Sandbox Code Playgroud)
<div contenteditable=true>Hello <span class="some-class">Dont delete me!</span> people!</div>
Run Code Online (Sandbox Code Playgroud)

我想阻止用户从中删除<span class="some-class">Dont delete me!</span>.

我猜我应该检查当用户在onChange事件上按回空格时要删除的文本.但我不知道如何检查删除的内容是否只是字母H或整个div<span class="some-class">Dont delete me!</span>

html javascript css

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

使用导致函数的参数始终返回false

当且仅当两个args是数字(因此我的第一个函数)时,我想总结我的函数的args.

function checkNum() {
 var num = 0;
 for (var i = 0; i < arguments.length; i++) {
  if (typeof arguments[i] !== 'number') {
   return false;
  } 
 }
 return true;
}

function addTogether() {
  var num = 100; 
  if ( checkNum() ) { 
    return arguments[0] + arguments[1];
  } else {
    return undefined;
 }
}
addTogether(2, "");
Run Code Online (Sandbox Code Playgroud)

然而,无论args值是什么,我的第二个函数都会执行求和.关于如何解决这个问题的任何提示?

javascript if-statement

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

如何使用JS修改HTML元素的样式(使用CSS外部样式)?

因此,当我单击<p>家庭班级的标签时,我希望它将颜色更改为绿色,但不起作用,请问为什么。单击可以很好地注册(因为console.log(“ test”)可以很好地显示),但是其余更改颜色的功能将无效。这是我的css,html和js代码(该js代码包含在HTML中,因此它不是外部文件或其他任何文件):

.greyRect {

  height:150px;
  width:1350px;

  background-color: #D3D3D3;


}
h1 {
  text-align: center;
}
h2 {
    text-align: center;
}
.home {



box-sizing: border-box;
width:80px;
height:35px;

line-height: 2;
  position: relative;
left:350;
  color:white;

}
.casinocraps {
  background-color: grey;

box-sizing: border-box;
width:120px;
height:35px;
text-align: center;
line-height: 2;
  position: relative;
left:460;
bottom:50;
  color:white;
}
.tictactoe {
  background-color: grey;
  box-sizing: border-box;
  width:90px;
  height:35px;
  text-align: center;
line-height: 2;
    position: relative;
left:600;
bottom:100;
    color:white;
}
.bingo {
  background-color: grey;
  box-sizing: border-box;
  width:80px;
  height:35px;
  text-align: center; …
Run Code Online (Sandbox Code Playgroud)

html javascript css

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

输入密码即可显示div内容

我想输入这个词,并显示PASSWORD里面的内容。HIDDENDIV

有人可以告诉我哪里出错了吗?

#HIDDENDIV {
    display: none;
}
Run Code Online (Sandbox Code Playgroud)
<input type="text" id="password" onkeydown="if (event.keyCode == 13) document.getElementById('button').click()" />
        <br/>
        <input id="button" type="button" value="Login" onclick="if (document.getElementById('password').value == 'PASSWORD') { 
document.getElementById('table').classList.toggle('show');   document.getElementById('passw').style.display='none'; } 
else {  alert('Invalid Password!'); password.setSelectionRange(0, password.value.length);   } " />

<div id="HIDDENDIV">bla</div>
Run Code Online (Sandbox Code Playgroud)

html javascript

-4
推荐指数
1
解决办法
6931
查看次数

标签 统计

javascript ×7

html ×5

css ×4

if-statement ×1

jquery ×1

php ×1