cor*_*eyg 1 javascript function intro.js
我已经尝试了这里的步骤: 在 intro.js 中使用点击功能步骤
获取在步骤中触发的函数。我没有成功地执行函数,但教程仍在运行。最终目标是让函数触发按钮点击。谢谢你的帮助。
<script type="text/javascript">
function startIntro(){
var intro = introJs();
intro.setOptions({
steps: [
{
intro: "Welcome to the page!",
onchange: function(){
console.log("test");
},
onbeforechange: function() {
console.log("before");
}
},
{
element: '#step1',
intro: "You can start doing something by clicking the New Item button."
},
{
element: '.thefilter',
intro: "You can filter any of the stock items in the table by using the search fields ",
position: 'bottom'
}
]
});
intro.start();
}
</script>
<a href="javascript:void(0);" onclick="startIntro();"><img style="position:fixed;" src="help.png" /></a>
Run Code Online (Sandbox Code Playgroud)
我错过了示例中的某些内容,这些内容为我提供了所需的方向。
这是更新的代码。
TLDR;删除了步骤中的内联 onchange 并将其附加在 intro.start 之前。作品!
<script type="text/javascript">
function startIntro(){
var intro = introJs();
intro.setOptions({
steps: [
{
intro: "Welcome to the page!"
},
{
element: '#step1',
intro: "You can start doing something by clicking the New Item button."
},
{
element: '.thefilter',
intro: "You can filter any of the stock items in the table by using the search fields ",
position: 'bottom'
}
]
});
intro.onbeforechange(function () {
if (this._currentStep === 2) {
console.log('what is happening')
return false;
}
});
intro.start();
}
</script>
<a href="javascript:void(0);" onclick="startIntro();"><img style="position:fixed;" src="help.png" /></a>
Run Code Online (Sandbox Code Playgroud)