You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Laravel Blade框架中实现Intro.js按钮引导功能?

Fixing Intro.js Initialization in Laravel Blade with jQuery

Hey there! Let's get your Intro.js working properly in Laravel Blade. The issue with your current jQuery code is that you're trying to use href() and onclick() as if they're jQuery methods—those are actually HTML attributes, not functions you can call inside a click handler. Here's how to fix it:

Step 1: Correct Your Button HTML

First, make sure your button (link) has the correct id and a proper href (we'll handle preventing the default action in the script):

<a class="btn btn-large btn-success" href="#" id="belajarr">Show me how</a>

Step 2: Fix the jQuery Click Handler

Replace your existing script with this. We'll stop the link from reloading the page with e.preventDefault() and directly call the Intro.js method, just like your original onclick did:

$(document).ready(function(){
    $('#belajarr').on('click', function(e){
        // Prevent the link from navigating to a new page
        e.preventDefault();
        // Initialize Intro.js with your desired option
        introJs().setOption('showProgress', true).start();
    });
});

Key Things to Double-Check

  • Intro.js is Loaded: Make sure you've included the Intro.js script and CSS in your Blade template. If you're using Laravel Mix, you might have imported it in resources/js/app.js like import introJs from 'intro.js'; and imported the CSS in resources/css/app.css with @import 'intro.js/introjs.css';. Alternatively, you can use CDN links in your layout blade file (just make sure they load after jQuery if you're using jQuery).
  • jQuery is Available: Ensure jQuery is loaded before your custom script. In newer Laravel versions, jQuery isn't included by default, so you might need to install it via npm (npm install jquery) and import it in your app.js, or add a CDN link for jQuery.

That should do it! When you click the button now, the Intro.js tour should start just like it did with the original inline onclick.

内容的提问来源于stack exchange,提问作者Ryan Ariel Winata

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:13:21