在jquery代码中调用脚本

时间:2014-05-10 17:54:09

标签: javascript jquery

以下代码应在更改切换容器时触发,这些容器显示调整大小的文本以适合框。

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://jquery-textfill.github.io/jquery-textfill/jquery.textfill.min.js"></script>

<script>
$(function(){
  $(".clsNumber").textfill();
});
</script>

<script>
$(document).ready(function(){
  $("button").click(function(){
    $(".clsToggle").slideToggle();
  });
});
</script>
</head>

<body>
  <div class="clsToggle">
    <div class="clsNumber" style="width:100px; height:50px; background-color:red;">
      <span>One</span>
    </div>
  </div>
  <div class="clsToggle" style="display:none;">
    <div class="clsNumber" style="width:100px; height:50px; background-color:green;">
      <span>Two</span>
    </div>
  </div>
  <button>click me</button>
</body>

我希望调整大小的文本适用于两个切换容器。

隐藏框(display:none;)忽略其他脚本(jQuery TextFill)的原因是什么?

1 个答案:

答案 0 :(得分:1)

使用以下

更改document.ready代码
$(document).ready(function(){
  $("button").click(function(){
    $(".clsToggle").slideToggle();
     $(".clsNumber").textfill();
  });
});

请找到完整的代码here