在 JS 工具提示构造函数中: $('.classname').ready(function(el-6ren">
gpt4 book ai didi

javascript - 从 HTML 类内部访问 Ruby 变量并在 JS 函数中使用它

转载 作者:行者123 更新时间:2023-11-28 05:02:00 24 4
gpt4 key购买 nike

我正在尝试从 HTML 访问 ruby​​“variablename”变量:

<% array.each_with_index do |variablename, i| %>
<span class="classname">
<a ng-href="/variablename/<%= variablename.gsub(' ', '').strip %>"> <%=variablename.strip %> </a>
</span>

在 JS 工具提示构造函数中:

$('.classname').ready(function(element) {
Tooltipconstructor.create('.classname', {
ajax: {
type: "GET",
dataType: "JSON",
url: /api/etc/{} // Where I want to access the HTML/Ruby Variable
etc..........

如何访问该变量?谢谢!

最佳答案

您还可以从a文本中获取值:

$('.classname').ready(function(element) {
var path = $('.classname > a').text()
Tooltipconstructor.create('.classname', {
ajax: {
type: "GET",
dataType: "JSON",
url: /api/etc/+path // Where I want to access the HTML/Ruby Variable
etc..........

关于javascript - 从 HTML 类内部访问 Ruby 变量并在 JS 函数中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42078799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com