- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不确定如何提出这个问题,所以也许这就是为什么我找不到答案的原因,而且一般来说我对 javascript 非常陌生,但这里有:
我正在尝试使用 javascript 更改我的主 div 的内容,方法是能够单击更改它的“链接”。当我使用
在线查看时,我以为我找到了解决方案$( "#but2" ).click(function() {
$("#Main").html("fffffffffffgdfg");
然而,当我尝试将内容添加到 html("")
中时部分,如果它有 <div class=""></div>
在它里面,它完全停止运作。如果它只是文本或程式化文本,它工作正常,但我希望能够一起更改内部,因为我使用程式化的 div 来创建一个有凝聚力的网页。我可以理解我所要求的事情是否以我要求的方式是不可能的,但是有没有办法做到这一点?
我正在做的一个例子
<div class="Main">content
<div class="sub">sub content</div>
</div>
当相应的按钮被按下时,“子”内容将被 javascript 更改。
更简单地说:有一个主页,然后单击一个显示“博客”的按钮,然后博客条目就会显示出来(但是该博客中有 div 属性),而不更改“主要”之外的内容。
如果我没有任何意义,我深表歉意。希望有人能帮忙!如果您需要更多信息,请告诉我。我非常渴望得到答案,而且我对 javascript 非常非常陌生。
编辑:
这里是实际使用的代码和我正在尝试做的大量示例。它最初只是 .html("wall of code"),但我也尝试了 append("wall of code"),并尝试使用 '' 而不是 ""
<script type="text/javascript">
$( document ).ready(function() {
$( "#but1" ).click(function() {
$("#Main").append('<div class="ddd"><h2>Sector Chimera</h2>
<img src="{image:Game 1}" width="{text:DivWidth}"><br><br>
<div class="din">
<b>Length:</b> Long = 20+ hours.<br>
<b>Game Type:</b> 3D/2D Persona-esque RPG.<br>
<b>Genre:</b> Sci-Fi/Thriller <br>
<b>Rating:</b> Aimed to be rated 16+ <br>
<b>Completion:</b> Currently being revamped.<br><br>
<b>Summary:</b> The City Chimera, a dream come true for any wayward souls, criminals, and terminally ill desperate for a solution to life's problems. Sign away your life in favor of ground breaking treatments, a paycheck, or just a roof over your head and warm food in your belly. But alas, nothing really comes free, and being a guinea pig has its very severe downsides. Afterall, you don't build a secret city to house experiments if you're up to good.<br><br>Take control of the new kid on the block and uncover the dark secrets that lie within the walls of Sector Chimera, along with a ragtag team of misfits and downtrodden heroes in the making... Should you choose it.</div>
</div>
<div class="ddd"><h2>Ventio Mortis</h2><img src="{image:Game 2}" width="{text:DivWidth}"><br><br>
<div class="din">
<b>Length:</b> Medium = 4-11 hours.<br>
<b>Game Type:</b> 2D Visual Novel.<br>
<b>Genre:</b> Horror/Otome <br>
<b>Rating:</b> Aimed to be rated 16+ <br>
<b>Completion:</b> 7%<br><br>
<b>Summary:</b> When bodies start surfacing on the streets of a normally quiet town, things start to get a little tense in the city – for both the residents above and below ground and the law. As a detective tails Hollowelle and her gang of undead misfits, she does her very best to avoid her way of life from crumbling beneath her. Add to her misfortunes betrayal from within her own family, a human detective on her case is the least of her worries.
</div>
</div>
<div class="ddd"><h2>Rise of Remix</h2><img src="{image:Game 3}" width="{text:DivWidth}"><br><br>
<div class="din">
<b>Length:</b> Long = 20+ hours.<br>
<b>Game Type:</b> 3D RPG.<br>
<b>Genre:</b> Sci-Fi/Action/Adventure <br>
<b>Rating:</b> Aimed to be rated 16+ <br>
<b>Completion:</b> 2%<br><br>
<b>Summary:</b> euismod tristique eros, vel mattis purus condimentum non. Nulla ullamcorper, tellus id lobortis ultricies, orci arcu luctus felis, in rhoncus magna odio et eros. Sed eros leo, mollis eu urna eget, varius tincidunt neque. Donec tempus faucibus turpis quis pellentesque. Aliquam sit amet ligula vestibulum, euismo facilisis porttitor. Nam a mattis nulla. Vestibulum consectetur sed arcu vel tristique. Aliquam rutrum, sapien a ultricies eleifend, ex sapien auctor lacus, ac condimentum lacus dolor ac mi.</div>
</div>
<div class="ddd"><h2>Betterflies</h2><img src="{image:Game 4}" width="{text:DivWidth}"><br><br>
<div class="din"><b>Length:</b> Short = 2-4 hours.<br>
<b>Game Type:</b> 2D Visual Novel.<br>
<b>Genre:</b> Otome Game <br>
<b>Rating:</b> Aimed to be rated 12+ <br>
<b>Completion:</b> 40%.<br><br>
<b>Summary:</b> Just when you thought your anxiety could be controlled, it just seems to control you again and again. After a particularly bad anxiety attack, you are sent to group therapy and forced to live in a rehabilitation center until your mental health improves. You are not alone, however, with a small group of soon-to-be friends (or more), and Dr. Sarah, your life long therapist, to help guide you on the way to better health, as long as you want it, of course. A support system is important, after all, in recovery.</div>
</div></div>')
});
$( "#but2" ).click(function() {
$("#Main").html("This is the updated text");
});
$( "#but3" ).click(function() {
$("#Main").html("This is the updated text");
});
$( "#but4" ).click(function() {
$("#Main").html("This is the updated text");
});
$( "#but5" ).click(function() {
$("#Main").html("This is the updated text");
});
$( "#but6" ).click(function() {
$("#Main").html("This is the updated text");
});
$( "#but7" ).click(function() {
$("#Main").html("This is the updated text");
});
});
</script>
以及我实际的 div,它们都位于“容器”中,而我想要更改的内容位于“d2”中
<div class="d2">
<div id="Main">
<div class="ddd"><h2>Sector Chimera</h2>
<img src="{image:Game 1}" width="{text:DivWidth}"><br><br>
<div class="din">content
</div></div></div>
最佳答案
听起来您想要“单页应用”之类的东西。在顶部有按钮或某些导航栏/标题的地方,以及根据用户单击的按钮而变化的主体。我没有做
$("#Main").html("fffffffffffgdfg");
我会创建一个单独的 .html 文件,其中包含将被动态加载的标记。这是更好的,因为它更“面向 future ”,如果博客变得很长,您不希望将所有标记作为 JavaScript 字符串传递。我会将上面的行更改为:
function load(name) {
// Build path to file
var path = name + '.html';
// Load the inner html from that file into the div with id='content'
$('#content').load(path);
}
在您的 index.html 中,我将执行以下操作:
<!-- These buttons will stay at the top like a header -->
<div>
<!-- Upon being clicked, they will pass their names to the load function -->
<button name='contact'onclick='load(name)'>Contact</a>
<button name='blog' onclick='load(name)'>Blog</a>
</div>
<!-- This will be the div that changes -->
<div id='content'></div>
现在,您所要做的就是创建文件:
contact.html
blog.html
您将能够单击按钮,内部 HTML 将发生变化
关于javascript - 如何在不破坏整个功能的情况下在 jquery .html() 函数中添加一个 div 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46517236/
我正在尝试完成撤消/重做。我正在使用loadFromJSON(...)从我存储在数组中的 Canvas 状态重新构建 Canvas 。基本上,我的想法是破坏现有的 Canvas 并重新构建 Canva
在某些情况下,我有一个在 iframe 中打开的网页。当它被加载到那个 iframe 中时,我需要它将窗口位置设置为资源以下载文件(所有这些都是为了更新 GreaseMonkey 脚本......所有
当我创建 Intent 时: Intent in = new Intent(this, myclass.class); this.startActivity(in); 我创建了一个新的 Intent
我正在我本地版本的 Wordpress 网站上为 Wordpress 创建新的短代码。 在 functions.php 中,我添加了例如: function shortTest() { re
我正在为机械网站制作 JavaScript 闪卡游戏。因为我想将方程写在卡片上,所以我需要使用 delta(Δ) 符号。 一张卡片可能有:一侧是“功率方程”,另一侧是“P=W/Δt”。如果卡片从第一面
我编写了以下代码: document.addEventListener("DOMContentLoaded", ()=>{ let menu = document.querySelector(
我的浏览器同步工作正常,但我仍然很难处理之前的 html 的缓存。即使选中了 Chrome 的“禁用缓存”,甚至在隐身模式下也是如此! 要加载页面更改,我总是必须“清除缓存并硬重新加载”。 我想知道,
我注意到每次打开和关闭(通过单击菜单项或单击菜单外的某个区域)时,上下文菜单 ( Ext.menu.Menu ) s 不会从 DOM 中删除,它们只是以某种方式变得不可见。 如何改变这个? 最佳答案
给定依赖记录类型: Record FinPath : Type := mkPath { fp_head : S i; fp_tail
在 Husdon/Jenkins 中,我可以在构建被破坏时设置通知,以向进行破坏构建的 checkin 的用户发送电子邮件。如何在 Teamcity 中执行此操作? 我知道个人用户可以通过 Teamc
我注意到每次打开和关闭(通过单击菜单项或单击菜单外的某个区域)时,上下文菜单 ( Ext.menu.Menu ) s 不会从 DOM 中删除,它们只是以某种方式变得不可见。 如何改变这个? 最佳答案
使用 MIMEMultipart('alternative') 发送 html 和 pain-text 时 将 html 转换为文本时,html 的 anchor 换行 http://127.0.0.
每当我的应用程序最小化时,我都会启动一个服务,该服务向我的 HTTP 服务器发送拉取请求以检查通知,当应用程序恢复时,服务将被终止(以及计划的可运行项)。一切正常,直到我决定终止该应用程序(将其从正在
我意识到该框架处于 alpha 阶段,但正在实现 jQuery Mobile破坏了我的omniauth 身份验证。当我尝试登录时,一旦我尝试点击/auth/twitter Controller ,jQ
我对 Angular 比较陌生,经过几个小时的调试,我发现添加 jquery 时存在一些不兼容性。该指令在没有 jquery 的情况下工作正常,但在使用 jquery 时会中断:/ 这是一个 plnk
我发现,因为我正在处理的所有表单都有一个包含“name =“submit””属性的提交按钮,所以当我单击应该触发表单提交的链接时,触发器提交会中断. 有谁知道我该如何解决这个问题。 下面的 JQuer
我遇到了一个问题:/我得到了一个 CSS 东西,它使悬停时背景位置发生变化。但是当我在 javascript 中运行一个改变悬停的函数后,CSS 停止工作。 这是函数: function tree()
谁能给出一个完整的例子来说明 qooxdoo 1.6 中的 dispose 和 destruct 是如何工作的? ,我在 qooxdoo 演示或文档中找不到任何好的示例。 谢谢你的建议。 最佳答案 处
我对 JFormattedTextField 有疑问(我将它用作我们所有文本字段的基类)。 今天我尝试向该字段的文档添加一个文档过滤器,它工作得很好,但前提是它没有设置格式化程序工厂。 问题是,当设置
我有一个点击事件 $('#ship_Move').click(function (event) { event.stopPropagation();
我是一名优秀的程序员,十分优秀!