基于条件jQuery的液体脚本

发布于 2025-02-01 16:05:48 字数 932 浏览 2 评论 0原文

我们假设我们有一个下拉切换:

<label for="num-of-records">Rows per Page: </label>
<select name="num-of-records" id="num-of-records">
  <option value="" selected>default</option>
  <option value="25">25</option>
  <option value="50">50</option>
</select>

而且我们也有一个liquid代码:

{% include 'page' key: 'table' %}

对于key,我提供了一些选项table> Table> Tabletable25table50对于每个下拉选项值值。

我是liquid的新手,但是我想创建一个jQuery,该根据下拉列表选择key值。

<script>
$(this).append("{% include 'page' key: 'table"+ $.("#num-of-records").val()+"' %}"
</script>

因此,假设我选择选项25,因此(也许重新打开页面)附加liquid of:

{% include 'page' key: 'table25' %}

Let's suppose we have a dropdown toggle:

<label for="num-of-records">Rows per Page: </label>
<select name="num-of-records" id="num-of-records">
  <option value="" selected>default</option>
  <option value="25">25</option>
  <option value="50">50</option>
</select>

And we also have a liquid code:

{% include 'page' key: 'table' %}

For key, I have provide some options table,table25, and table50 for each dropdown options value.

I am new to liquid, but I want to create a jquery which select the key value based on the dropdown.

<script>
$(this).append("{% include 'page' key: 'table"+ $.("#num-of-records").val()+"' %}"
</script>

So let's say I choose option 25, so it will (maybe reopen the page) append liquid script of:

{% include 'page' key: 'table25' %}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满栀 2025-02-08 16:05:48

液体是服务器端渲染语言。 jQuery是在液体之后渲染的,因此您无法以此方式进行。

一种可以起作用的方法(不是轻的方法)可能是渲染所有液体外壳,隐藏它们,然后通过使用jQuery显示您想要的一种。

Liquid is a server side rendered language. jQuery is rendered after Liquid so you cannot proceed this way.

An approach that could work (not a light one however) could be to render all your Liquid cases, hide them, then show the one you want by using jQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文