从html'value'属性中检索值 [英] Retrieve value from html 'value' attribute

查看:130
本文介绍了从html'value'属性中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检索名为'value'的html元素属性中定义的实际值?

How can I retrieve the the actually value defined within the html element attribute named 'value'?

在用户注册之前,我正在设置一个会话变量一个值应该是发布者或读者,具体取决于他们点击的div。该会话值将在用户创建时使用。

Before a user signs up, I am setting a session variable with a value that shall be either 'publisher' or 'reader' depending on which div they click on. This session value will be used upon user creation.

<template name="authJoinType">
<div class="container join-type">
    <div class="row"> 

        <div class="col-xs-6 col-sm-6 col-md-6">
            <a href="{{pathFor route = 'join'}}">
            <div class="join-type-inner" id="userTypeSelect" value="reader">Reader</div>
        </a>
        </div> 

        <div class="col-xs-6 col-sm-6 col-md-6">
            <a href="{{pathFor route = 'join'}}">
            <div class="join-type-inner" id="userTypeSelect" value="publisher">Publisher</div>
        </a>
        </div>

    </div>
</div>
</template>

client.js(尝试将会话变量设置为'reader'或'publisher',具体取决于哪个他们点击的两个人中的div)

client.js (Trying to set the session variable to either 'reader' or 'publisher' depending which div out of the two they click on)

Template.authJoinType.events({
'click div.join-type-inner': function(e, tmpl) {
    var userType = $(e.target).find('#userTypeSelect').val();
    Session.set('userType', userType);
    var selectedUserType = Session.get('userType');
    console.log(selectedUserType); // this is printing out 'undefined'
}
});

帮助?我是否以不正确的div为目标?

Help? Am I targeting the incorrect div to begin with?

推荐答案

更改:

var userType = $(e.target).find('#userTypeSelect').val();

收件人:

var userType = $(e.target).attr("value");

这篇关于从html'value'属性中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆