Meteor - 从自定义属性中获取值

时间:2022-11-27 16:37:22

I got a problem, I making a litte game where you come through stages, and in every stage you have to make a choose. I want to save some of the information that the user pick, in "hola" and "chao", and later in the helpers save that info in sessions. But I dont know how to get the value of "hola"---> {{fidelidadSegmento}}

我遇到了一个问题,我做了一个小小的游戏,你经历了各个阶段,在每个阶段你都要做出选择。我想在“hola”和“chao”中保存用户选择的一些信息,稍后在帮助程序中保存会话中的信息。但我不知道如何获得“hola”---> {{fidelidadSegmento}}的价值

<select class="form-control" id="select0" name="categ">
    <option value = "0" selected="selected"> Stay </option>
        {{#each op in opciones}}
        <option value="{{op.costo}}" hola="{{fidelidadSegmento}}" chao="{{op.nombre}}"> {{fidelidadSegmento}} con {{op.nombre}} , eficiencia: {{op.eficiencia}}</option>costo
        {{/each}}
</select>

what I see in the browser is :

我在浏览器中看到的是:

 <select id="select0" class="form-control" name="categ">
 <option selected="selected" value="0"> Stay </option>
 <option value="3" hola="Awereness" chao="tv"> Awereness con tv , eficiencia: 0.8</option>

<option value="2" hola="Awereness" chao="magazine"> Awereness con magazine , eficiencia: 0.7</option>

 </select>

And I want to get the value of the attribute "hola" and "chao"

我想得到属性“hola”和“chao”的值

console.log($(this).attr('hola')); get me undefined and $(event.target).find("hola") get me [object Object]

的console.log($(本).attr( 'HOLA'));让我未定义和$(event.target).find(“hola”)让我[对象]

1 个解决方案

#1


0  

If you are trying to use jQuery then try accessing the selected option using:

如果您尝试使用jQuery,请尝试使用以下命令访问所选选项:

$("select option:selected")

But remember the default option does not have the attributes 'hola' or 'chao'. You will have to test for the attribute to be undefined or add the 'hola' and 'chao' attributes to the default option.

但请记住,默认选项没有属性'hola'或'chao'。您必须测试未定义的属性,或者将'hola'和'chao'属性添加到默认选项。

// This will return undefined for the default option
$("select option:selected").attr("hola"); 

This post might be helpful to you also.

这篇文章也可能对你有所帮助。

#1


0  

If you are trying to use jQuery then try accessing the selected option using:

如果您尝试使用jQuery,请尝试使用以下命令访问所选选项:

$("select option:selected")

But remember the default option does not have the attributes 'hola' or 'chao'. You will have to test for the attribute to be undefined or add the 'hola' and 'chao' attributes to the default option.

但请记住,默认选项没有属性'hola'或'chao'。您必须测试未定义的属性,或者将'hola'和'chao'属性添加到默认选项。

// This will return undefined for the default option
$("select option:selected").attr("hola"); 

This post might be helpful to you also.

这篇文章也可能对你有所帮助。