为jquery添加rails输入名称时出现问题
Trouble adding rails input name for jquery
我正试图从Rails4表单中获取点击单选按钮的id
$("input:radio[name=client_account]").click(function() {
var value = $(this).val();
alert(value);
var id= $(this).attr('id');
alert(id);
});
但是单选按钮的"名称"是"client_account[client_account_attributes][org_type]"
我有一个在表单中呈现的"f.collection_radio_buttons"集。我想创建一个"动态表单",根据某些问题的答案显示和隐藏div。但我需要在单击所选单选按钮时以某种方式从中获取id或值,以便确定要显示/隐藏哪些div。
以下是HTML的一个例子,以防它会有所帮助:
<input type="radio" value="Other" name="client_account[client_account_info_attributes][org_type]" id="client_account_client_account_info_attributes_org_type_other">
提前感谢!!
我最终将此作为我的最终解决方案
$("input:radio[name='client_account[client_account_info_attributes][org_type]']").click(function(event) {
var value = (event.target.value);
});
如果元素有特殊字符,则可以引用元素的名称。
var $button = $("[name='client_account[client_account_info_attributes][org_type]']");
$button.click(function () {
console.log($(this));
});
相关文章:
- 神秘的ajax json请求问题jQuery
- 这个代码出了什么问题?(Jquery)
- 图片库问题jquery
- SetInterval 60秒倒计时问题jQuery
- 这行代码出了什么问题?(jQuery.parseJSON)
- onclick属性的引号过多的问题 - jQuery,HTML
- IE8 问题 - jQuery 调整页面大小时导航 html
- nivo滑块和光滑的轮播无法协同工作的问题 - jquery
- Google Charts - hAxis 上的数字/字符串问题(Jquery ajax JSON 数据)
- window.位置问题JQuery代码
- 延迟对象使用问题jQuery
- 文件订单加载问题-jquery
- ie7问题:jquery点击编辑不工作
- jquery.mouseenter()问题jquery.mouseleave()和子元素
- Webkit问题:jQuery没有定义
- 拖放问题jquery
- 检索按钮值问题Jquery
- 选择所有复选框问题(jQuery)
- 过滤逻辑问题jQuery
- 逻辑运算符OR问题:jQuery