【发布时间】:2016-08-12 17:40:43
【问题描述】:
我最近开始学习 jQuery,但遇到了一些问题。 由于我是C/C++背景,所以对jQuery的代码格式不熟悉。
所以,我的问题是 .append() 似乎根本没有附加。我最近一直在编写一个在 jQuery 中制作弹出窗口的脚本,并且需要将一个元素附加到正文。没啥事儿。经过进一步测试 .append() 似乎没有工作。我的结论是我可能在滥用它,但我不知道如何。
$('#contact').click(function (e) {
$('#about').append('<h1>test</h1>');
e.preventDefault();
});
编辑 1:请求了 Html
<!DOCTYPE html>
<html>
<head>
<title>Canteen Mate</title>
<link rel="stylesheet" type="text/css"
href="https://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" type="text/css"
href="https://fonts.googleapis.com/css?family=Roboto+Condensed">
<link rel="stylesheet" type="text/css"
href="https://fonts.googleapis.com/css?family=Ubuntu">
<link rel="stylesheet" type="text/css" href="css/home.css">
</head>
<body>
<div class = "nav_wrapper" id = "nav_wrapper">
<nav>
<ul>
<li class = "current"><a href="#nav_wrapper" id = "Home" class = "nav">Home</a></li>
<li><a href="#about" id = "About" class = "nav">About</a></li>
<li><a href="#contact" id = "Contact" class = "nav">Contact</a> </li>
</ul>
</nav>
</div>
<div class = "wrapper">
<img src="images/newfood.jpg" alt="Food" class="luncho">
<div class = "text">
<h1 class = "motto">Ordering from the canteen has never been so simple<br>
<p class = "motto-description" id = "about">Order food from your canteen from
anywhere as long as you have data.</p></h1>
</div>
</div>
为了节省空间,只包含了一些 html(我要附加到的区域中的 html)。
<script> 元素位于底部。
【问题讨论】:
标签: javascript jquery html css