首页 \ 问答 \ jquery在没有硬编码的情况下显示/隐藏div中的内容(jquery show/hide content in div without hardcoding)

jquery在没有硬编码的情况下显示/隐藏div中的内容(jquery show/hide content in div without hardcoding)

我有3个div,里面有内容(图像)。 当您点击其中一个内容时,其内容将变为可见,其他两个内容将被隐藏。 我已经设法用jquery代码来实现它(你可以在下面检查它),但是它是硬编码的坏东西,有没有其他方法可以做到这一点?

PS:“ https://solomia-gera.github.io/ ”是网站本身,如果你想看看。

-------------------------------------------------- - - - -代码 - - - - - - - - - - - - - - - - - - - - - ------------

<!-- Hide/Show DIV1 content-->
<script>
// Hide content in div with id#mox when cliked on div with id#content
  $("#mox2").on("click", function () {
  $("#content1").hide();
  });
  $("#mox3").on("click", function () {
  $("#content1").hide();
  });
// Show content in div with id#mox when cliked on div with id#content
  $("#mox1").on("click", function () {
  $("#content1").show();
  });
</script>

<!-- Hide/Show DIV2 content-->
<script>
  $("#content2").hide();
// Hide content in div with id#mox when cliked on div with id#content
  $("#mox1").on("click", function () {
  $("#content2").hide();
  });
  $("#mox3").on("click", function () {
  $("#content2").hide();
  });
// Show content in div with id#mox when cliked on div with id#content
  $("#mox2").on("click", function () {
  $("#content2").show();
  });
</script>

<!-- Hide/Show DIV3 content-->
<script>
$("#content3").hide();
// Hide content in div with id#mox when cliked on div with id#content
 $("#mox2").on("click", function () {
 $("#content3").hide();
  });
 $("#mox1").on("click", function () {
 $("#content3").hide();
 });
  // Show content in div with id#mox when cliked on div with id#content
 $("#mox3").on("click", function () {
 $("#content3").show();
 });


I have 3 divs, there is content(images) inside of them. When you click on one of them content of it becomes visible and content of other two becomes hidden. I've been managed to achieve that with jquery code(you can check for it below), but the bad thing it's hardcoded, is there any other methods do do it?

P.S.: "https://solomia-gera.github.io/" is the site itself if you want to have a look.

---------------------------------------------------------THE CODE-----------------------------------------------------

<!-- Hide/Show DIV1 content-->
<script>
// Hide content in div with id#mox when cliked on div with id#content
  $("#mox2").on("click", function () {
  $("#content1").hide();
  });
  $("#mox3").on("click", function () {
  $("#content1").hide();
  });
// Show content in div with id#mox when cliked on div with id#content
  $("#mox1").on("click", function () {
  $("#content1").show();
  });
</script>

<!-- Hide/Show DIV2 content-->
<script>
  $("#content2").hide();
// Hide content in div with id#mox when cliked on div with id#content
  $("#mox1").on("click", function () {
  $("#content2").hide();
  });
  $("#mox3").on("click", function () {
  $("#content2").hide();
  });
// Show content in div with id#mox when cliked on div with id#content
  $("#mox2").on("click", function () {
  $("#content2").show();
  });
</script>

<!-- Hide/Show DIV3 content-->
<script>
$("#content3").hide();
// Hide content in div with id#mox when cliked on div with id#content
 $("#mox2").on("click", function () {
 $("#content3").hide();
  });
 $("#mox1").on("click", function () {
 $("#content3").hide();
 });
  // Show content in div with id#mox when cliked on div with id#content
 $("#mox3").on("click", function () {
 $("#content3").show();
 });


原文:https://stackoverflow.com/questions/42807240
更新时间:2022-11-15 14:11

最满意答案

如果这没有帮助,让我提前道歉,但我认为词汇分析具有正则表达的力量,因此,我怀疑你想要做的不是RE或Leex的甜蜜点。 第一步是从源代码转到词汇元素(标记),这些元素大部分都缺乏上下文,并且适合使用Leex。

我认为处理FOR和IN标记的不同上下文敏感语义将通过解析和Erlang的Yecc来处理。 您可以在词法分析阶段处理评论,但我认为通常您可以使用Leex和Yecc的组合。


Let me apologize in advance if this isn't helpful, but I think of lexical analysis as having the power of regular expression and, as such, I suspect that what you are trying to do is not in the sweet-spot of RE's or Leex. First pass would be to go from source-code to lexical elements (tokens) which would be mostly be devoid of context and would be an appropriate use of Leex.

I think the handling of the different, context-sensitive semantics of your FOR and IN tokens would be handled via parsing and Erlang's Yecc. You may be able to handle comments in the lexical analysis phase, but I think in general you might use a combination of Leex and Yecc.

相关问答

更多
  • 在文档页面的末尾,您可以找到以下注释: 使用^和$锚定正则表达式并未在当前版本的Leex中实现,只是生成一个解析错误。 这似乎意味着你不能像你一样使用^和$之间的正则表达式。 如果您知道字符串以特定字符结尾(例如\n ),我假设您可以使用该字符分隔符替换$ 。 At the end of the documentation page you find this note: Anchoring a regular expression with ^ and $ is not implemented in th ...
  • 如果这没有帮助,让我提前道歉,但我认为词汇分析具有正则表达的力量,因此,我怀疑你想要做的不是RE或Leex的甜蜜点。 第一步是从源代码转到词汇元素(标记),这些元素大部分都缺乏上下文,并且适合使用Leex。 我认为处理FOR和IN标记的不同上下文敏感语义将通过解析和Erlang的Yecc来处理。 您可以在词法分析阶段处理评论,但我认为通常您可以使用Leex和Yecc的组合。 Let me apologize in advance if this isn't helpful, but I think of l ...
  • 反斜杠用作字符串文字中的转义字符,例如"\n"表示包含换行符的字符串。 如果你想要一个文字反斜杠,你需要将它作为"\\"转义。 这是正则表达式中的问题"^[0-9]*(\.[0-9]+)?" ,Haskell解析器试图解释"\." 作为正常的字符串转义和扼流圈(可能是因为没有这样的逃逸)。 如果你把正则表达式写为"^[0-9]*(\\.[0-9]+)?" 错误消失了。 类型问题的原因是你从lex (drop (length token) s)的标准Prelude调用lex ,它具有String -> [(S ...
  • 您可以使用Set String来存储单词列表,并使用member函数来确定单词是否在一个集合中。 这是一些示例代码。 lexer的输入是动词,名词和介词的列表以及单词列表,然后根据单词所在的列表对其进行分类。 import qualified Data.Set as S data Speech = Verb | Noun | Preposition | Other -- classify a single word classify :: S.Set String -> S.Set String ...
  • CodeMirror将在更改的文档片段上重新运行其模式,您不需要自己的更改检测。 阅读此博客文章 ,了解CodeMirror模式的说明。 CodeMirror will re-run its mode on pieces of the document that are changed, you do not need your own change detection. Read this blog post for an explanation of CodeMirror modes.
  • 对于可重入词法分析器,所有通信必须包括扫描程序中包含的状态 。 在程序中的任何位置( 例如在main ),您可以通过要通过扫描仪的特殊功能访问状态变量。 例如 ,在原始的reentrant.l ,您可以这样做: yyscan_t scanner; yylex_init(&scanner); yyset_in(fopen(argv[1], "rb"), scanner); yylex(scanner); yylex_destroy(scanner); 我已重命名scanner以避免在操作中与yyscanne ...
  • 根据ocamllex手册 ,将lex_cell放在第一位就足够了: 如果多个正则表达式与输入的前缀匹配,则应用“最长匹配”规则:选择与输入的最长前缀匹配的正则表达式。 如果是tie,则选择规则中较早出现的正则表达式。 According to the ocamllex manual, it's sufficient to put lex_cell first: If several regular expressions match a prefix of the input, the “longest m ...
  • 我建议编写解析表达式语法(PEG) ,并在PHP中查看PEG库的答案 。 PEG与正则表达式非常相似,它们本质上是贪婪的,并且从不含糊:对于域特定语言(DSL)来说非常棒。 一般来说,使用一些正则表达式来创建缓存的php模板的速度方法并不慢吗? 否:正则表达式的速度是依赖于正则表达式引擎的实现。 通常,每次使用正则表达式时,都需要自己解析,然后使用给定的模型,它必须使用一般匹配器 ,它可以与所有正则表达式一起使用。 给定一个词法分析器,你可以对匹配器进行微调:你得到一个特定的匹配器 ,它只适用于你预定义的语 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。