dousi6701 2018-11-13 09:19
浏览 74
已采纳

缓存单选按钮jquery

I have this code:

@if (isset($isModelTranslatable) && $isModelTranslatable)
<div class="language-selector">
    <div class="btn-group btn-group-sm" role="group" data-toggle="buttons">
        @foreach(config('voyager.multilingual.locales') as $lang)
            <label class="btn btn-primary{{ ($lang === config('voyager.multilingual.default')) ? " active" : "" }}">
                <input type="radio" name="i18n_selector" id="{{$lang}}" autocomplete="off"{{ ($lang === config('voyager.multilingual.default')) ? ' checked="checked"' : '' }}> {{ strtoupper($lang) }}
            </label>
        @endforeach
    </div>
</div>
@endif

I want do. If people click on radio button, remember this radio, and when reload page, do active radio button, which he selected. How I can do this? I can do with laravel cache? Or I need use jQuery caching?

  • 写回答

1条回答 默认 最新

  • doucheng8471 2018-11-13 19:02
    关注

    jQuery doesn't have caching built in, but localStorage, like @Pete mentioned in the comments, is a good option. If you want to store data with Laravel, I'd suggest using an Eloquent model over caching, as it makes it easier (in my opinion) to associate unique data with a specific site visitor. (This is also assuming you have some sort of user login system preexisting.)

    If you do choose to go the Laravel route, you'll have to send data over to your server when a user makes a selection, and then store it on the Laravel side. Research the fetch API or just make a simple HTML form.

    For the most basic solution, localStorage remains your best bet. It's JavaScript-powered and stored on the client side, so you don't have to worry about cross-contaminating saved data or even storing data on your server at all. Wins all around! Take a look at this related answer on saving input states with localStorage, and let us know once you run into a specific issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号