首页 \ 问答 \ 将样式应用于选中的单选按钮的父级(Applying styling to a checked radio button's parent)

将样式应用于选中的单选按钮的父级(Applying styling to a checked radio button's parent)

所以我在<li>元素中有一系列单选按钮。 我正在尝试在所述<li>上创建一个边框,只有当它的子单选按钮被选中时。

我在jQuery中有一个中途解决方案:

$('input[type="radio"]').change(function() {
    if($(this).is(':checked')) 
    { 
        $(this).parent().css('border', '1px solid black');
    } 
    else 
    {
        $(this).parent().css('border', 'none');
    }
});

但是,这只会添加样式,但在选择单选按钮中的其他选项时不会删除它。 因此,如果您单击所有选项,它们最终都会应用该样式。

我能在这做什么?


So I have a series of radio buttons inside <li> elements. I'm trying to create a border on said <li> only when its child radio button is checked.

I have a halfway solution here in jQuery:

$('input[type="radio"]').change(function() {
    if($(this).is(':checked')) 
    { 
        $(this).parent().css('border', '1px solid black');
    } 
    else 
    {
        $(this).parent().css('border', 'none');
    }
});

However, this only will add the style, but will not remove it when a different option in the radio buttons is selected. So, if you click all of the options, they all end up having the style applied.

What can I do here?


原文:https://stackoverflow.com/questions/40245293
更新时间:2023-01-16 18:01

最满意答案

有很多方法可以处理一次性登录,这很大程度上取决于如何在服务器端实现体系结构以使其工作。 由于安全原因,通常Login API closely coupled 。 让我举一个例子,我的意思是closely coupled

当您想要Login Mobile App工作一次,并且下次用户打开Mobile app您不希望再次提示用户使用SignIn屏幕。 当然,您不希望将移动应用上的UsernamePassword等机密信息Username为持久数据,因为它可以从Android设备轻松获取。 那你干什么。

让我们假设您传递了具有Android Device唯一的deviceID登录凭据。 如下所示的东西。 以下是发送到LoginAPIJSON数据

{
    "username": "example@example.com",
    "password": "it's not a secret",
    "deviceId": "123456789"
}

现在,由于您不想保存Login凭据,服务器将生成随机字母数字String ,每次您登录移动应用程序时都会将其传递给您。

{
    "Success": true,
    "SuccessMessage": "credentials are correct, really!",
    "ErrorMessage": null,
    "Date": "dd/mm/yyyy",
    "token": "1eghe4qha23aehraeh456789" // now this is a nasty String
}

您现在可以将datetoken作为持久数据保存在Mobile App中。 因此,下次用户打开应用程序时,您可以让用户绕过SignIn屏幕,在后台,您可以通过将用户令牌ID发送到服务器来检查用户令牌ID是否正确,如下所示。 您可以选择SharedPreferences或创建文件并将其保存在那里

{
    "API_TYPE": "login",
    "deviceId": "123456789",
    "token": "1eghe4qha23aehraeh456789"
}

服务器可以针对deviceID检查此令牌ID,以检查这是否是设备的正确令牌并进行响应。

您可能会问为什么我们再次检查token ,因为这是由服务器首先发出的,表明凭据是正确的。 我同意你有一个观点,假设它是一个故障安全条件,如果用户从网站更改密码或导致更改服务器上的令牌以供该用户更改的东西,如果服务器拒绝提供的令牌你只是要求用户再次登录。

这将确保用户在任何给定的时间点仅登录到一个Android Device


There are many ways to deal with one time login, it depends a lot on how the architecture is implemented on server side to make it work. Usually Login API are closely coupled for security reason. let me example what I mean by closely coupled.

As you want to Login in to Mobile App work once and the next time user opens the Mobile app you don't want to prompt user with SignIn screen again. and surely you don't want to save the confidential information like Username and Password on Mobile app as persistent data, as it can be fetched easily from android device. so what you do.

Lets assume you pass login credentials with a deviceID unique to the Android Device. Something like shown below. following is the JSON data sent to the LoginAPI

{
    "username": "example@example.com",
    "password": "it's not a secret",
    "deviceId": "123456789"
}

Now as you don't want to save the Login credentials, server will generate a random alpha numeric String pass it to you in response every time you login to the Mobile App.

{
    "Success": true,
    "SuccessMessage": "credentials are correct, really!",
    "ErrorMessage": null,
    "Date": "dd/mm/yyyy",
    "token": "1eghe4qha23aehraeh456789" // now this is a nasty String
}

you may now save the date and the token in Mobile App as persistent data. So next time your user opens the app you may let user bypass the SignIn screen, and in background you can check if users token id is correct by sending that to the server, something like this. you may choose SharedPreferences or create a file and save it there

{
    "API_TYPE": "login",
    "deviceId": "123456789",
    "token": "1eghe4qha23aehraeh456789"
}

Server may check this token id against the deviceID to check if this was the correct token for the device and respond.

You may ask why are we checking the token again as this was sent by the server in first place stating the credentials were correct. I agree you do have a point, lets say it is a fail safe condition, if the user changes the password from the website or something which causes to change the token on server for that user to change, if the server denies the token provided by you just ask the user to login again.

This will make sure that a user is logged in to only one Android Device at any given point of time.

相关问答

更多
  • Roy T. Fielding和Richard N. Taylor的现代Web架构的原始设计,即来自所有REST术语的作品序列来自于,包含客户端 - 服务器交互的定义: 所有REST互动都是无状态的 。 也就是说,每个请求都包含连接器了解请求所需的所有信息,而不管任何可能在其前面的请求 。 这个限制完成了四个功能,第一和第三个功能在这种特殊情况下很重要: 第一 :它不需要连接器来保持请求之间的应用程序状态 ,从而减少物理资源的消耗并提高可扩展性; 第三 :它允许中间人孤立地查看和理解请求 ,这在服务被动态重 ...
  • 有很多方法可以处理一次性登录,这很大程度上取决于如何在服务器端实现体系结构以使其工作。 由于安全原因,通常Login API closely coupled 。 让我举一个例子,我的意思是closely coupled 。 当您想要Login Mobile App工作一次,并且下次用户打开Mobile app您不希望再次提示用户使用SignIn屏幕。 当然,您不希望将移动应用上的Username和Password等机密信息Username为持久数据,因为它可以从Android设备轻松获取。 那你干什么。 让 ...
  • 在Redmine API wiki上,您可以看到以下内容: 大多数情况下,API需要认证。 要启用API样式认证,您必须在管理 - >设置 - >认证中检查启用REST API。 然后,认证可以通过两种不同的方式完成: 使用您的常规登录/密码通过HTTP基本认证。 使用您的API密钥,这是一种方便的方式,以避免在脚本中输入密码。 可以通过以下方式之一将API密钥附加到每个请求中: 作为“关键”参数传入 通过HTTP基本认证作为用户名使用随机密码传入 作为“X-Redmine-API-Key”HTTP标头传入 ...
  • 我知道这是一篇相当过时的帖子,但是对于今后访问此页面的任何人,我都为Schoology开发了一个非常基本的两条腿OAuth包装器: https://github.com/rvanasa/schoology-api 这不是专为Android开发而设计的,但根据我的理解,您可以将Maven模块作为项目依赖项的一部分。 这是一个快速示例用法: SchoologyRequestHandler schoology = new OAuthSchoologyRequestHandler(new BasicOAuthRes ...
  • 使用解决; request.basic_auth 'username', 'password' request["Content-Type"] = "application/json" 代替: request["user"] = "" request["password"] = "" Resolved by using; request.basic_auth 'username', 'password' request["Content-Type"] = "app ...
  • 这个答案 Yii::$app->request->getUserAgent(); This the answer Yii::$app->request->getUserAgent();
  • HTTP本质上是一种无状态协议。 也就是说,没有诸如浏览器会话和cookie之类的技术,没有任何一个请求会对另一个产生影响。 https://en.wikipedia.org/wiki/Stateless_protocol API因为没有浏览器来查看它们,所以无法使用诸如“登录”之类的东西,因为它依赖于使用API时不存在的客户端技术。 您应该为每个请求使用一种认证形式,例如: 作为每个请求的查询参数附加的秘密令牌/密码 OAuth的 HTTP基本身份验证 或类似的东西。 这个问题提供了一个在Rails中使用 ...
  • 也许你需要cookie支持? 像这样的东西:
  • 听起来你正在使用Django REST Framework,在这种情况下TokenAuthentication可能是合适的。 从文档: 此认证方案使用简单的基于令牌的HTTP认证方案。 令牌认证适用于客户端 - 服务器设置,例如本机桌面和移动客户端 您不需要预先生成令牌,因为客户端可以使用您在urls.py中配置的内置视图obtain_auth_token来请求令牌。 一旦客户端获得会话标记,他们就可以使用Authorization: HTTP标头在随后的API调用中提供它。 查看文档以获取更多信息: ht ...
  • 在向REST API发出请求时,我通常使用Square的OkHttp 。 您可以使用所需的JSON对象进行POST。 在Posting a String部分查看配方页面 。 更改application/json的Mediatype,构建您的JSONObject并将其传递给Request Request request = new Request.Builder() .url("https://api.parse.com/1/push") .post(RequestBody.c ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)