weixin_33716154 2017-05-04 15:37 采纳率: 0%
浏览 43

如何在文本中实现两种语言?

这个问题已有答案:Event binding on dynamically created elements?

我有一个页面,其中有一些文本需要用两种语言。这是我的代码:

$('#english').hide();

$('#enButton').on('click', function() {

  $('#english').fadeIn();
  $('#french').fadeOut();

});
#french {
  margin-top: 40px;
}

#english {
  display: block;
  position: absolute;
  top: 90px;
  left: 150px;
}

#frButton {
  top: 30px;
  left: 145px;
  position: absolute;
  cursor: pointer;
}

#enButton {
  top: 30px;
  position: absolute;
  right: 135px;
  cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="content">
  <div id="container">
    <div id="about" class="sections">
      <div id="frButton">
        <p>FRA</p>
      </div>
      <div id="enButton">
        <p>ENG</p>
      </div>
      <div id="textContainer">
        <div id="french">
          <p>Text in French.... </p>
        </div>
        <div id="english">
          <p>Text in English...</p>
        </div>
      </div>
      <!-- end of textContainer -->
    </div>
  </div>
  <!-- end of content -->
</section>
<!-- end of container -->

最后两条规则适用于按钮:当单击“English”按钮时,我想触发一些jQuery,以隐藏法语文本并使英文出现,然后在单击“frButton”时执行相反的操作——但是这不起作用,而且我把这两种文本放在一起,但是方法$( '#english' ).hide();不起作用。我已经困扰好久了,而#English id根本没有被锁定。知道为什么吗?

顺便说一下,“About”的内容是使用Ajax加载的。

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33743880 2017-05-04 15:44
    关注

    $( '#english' ).hide();

    is not working because #english is not present when the page loads. Your event should be written like this :

    $('#about').on('click', '#enButton', function(){});

    You can't attach an event to an element that is loaded in ajax, you attach it to the parent that is there at start then target the button.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错