如何在点击按钮时调用特定的课程? 至今 , 我的jQuery代码是:
$(document).ready(function() {
$('.btn').click(function () {
//script to call a class
});
})
现在我有一个html类。我需要的是在点击按钮时调用该类。
<div class="page-loader-wrapper">
<div class="loader">
<div class="preloader">
<div class="spinner-layer pl-red">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
<p>Please wait...</p>
</div>
</div>
我该怎么做?
答案 0 :(得分:0)
您可以使用jquery add class method
将类添加到html元素callback()
其中p是选择器,intro是类名。
答案 1 :(得分:0)
$('.btn').click(function() {
//script to call a class
var myClass = $(".page-loader-wrapper");
// display the class or whatever
myClass.toggle();
//if you mean calling a function instead of class it can be done like this.
myFunction();
});
// test function
function myFunction(){
console.log("This is a test...");
}
.page-loader-wrapper {
border: 1px solid red;
height: 200px;
width: 200px;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class='btn'>PRESS ME</button>
<br>
To access a class and modifiy it you just need to reference the class name and then you can do stuff with it. Like this:
<pre>
var myClass = $(".page-loader-wrapper");
myClass.toggle();
</pre>
<div class="page-loader-wrapper">
<div class="loader">
<div class="preloader">
<div class="spinner-layer pl-red">
<div class="circle-clipper left">
<div class="circle"></div>
</div>
<div class="circle-clipper right">
<div class="circle"></div>
</div>
</div>
</div>
<p>Please wait...</p>
</div>
</div>