javascript - Rails - 使用 javascript 禁用 select_tag

标签 javascript jquery html ruby-on-rails

如何使用 javascript 禁用 select_tag 示例:

<button onclick="DisableFields()">Disable</button>  

<p class="col-lg-2" id ="test1" >
   <%= 
      select_tag(:customer_service_beneficiary_id,  options_for_select(customer_service_beneficiary_col) , :class => "form-control")
   %>
</p>

我试过了,但没用:

function DisableFields() {
  console.log('Disable');
  $("test1").prop('disabled', true);
  $("test2").attr('disabled','disabled');
}

最佳答案

试试这个你没有选择div not select

$('select[name="name-of-select"]').attr("disabled","disabled")

关于javascript - Rails - 使用 javascript 禁用 select_tag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36543161/

相关文章:

javascript - Bootstrap 4 .modal ('hide' ) 不工作

javascript - ModuleNotFoundError : Module not found: Error: Can't resolve '../components/charts/be.js' in '/vercel/workpath0/my-app/pages'

javascript - 如何获取 Angular 中可见元素的连续索引并忽略隐藏元素 *ngFor 的索引?

javascript - Service Worker 可以获取和缓存跨源 Assets 吗?

jquery Iphone itunes 滚动效果

javascript - 切换 jquery 容器内的链接不起作用

javascript - JQuery 同位素容器高度问题 w/iDangero.us Swiper

html - 是否需要在网页开头添加HTML doctype

jquery - 语法错误: Unexpected token in JSON at position x

javascript - 检查是否点击了自动创建的 div