简体   繁体   English

Rails Javascript空字符串传递给getElementById()

[英]Rails Javascript Empty string passed to getElementById()

I have a Rails 3.2 app. 我有一个Rails 3.2应用程序。 The following javascript was working fine. 以下javascript工作正常。 Now, it's getting 'Empty string passed to getElementById().' 现在,它正在获得'Empty string passed to getElementById().' Also getting Use of getPreventDefault() is deprecated. Use defaultPrevented instead. 同时不建议Use of getPreventDefault() is deprecated. Use defaultPrevented instead. Use of getPreventDefault() is deprecated. Use defaultPrevented instead. in the console. 在控制台中。

I'm not sure what changed? 我不确定发生了什么变化?

 $('#costproject_rebudget_funds').change ->
    alert "hey"
    checkbox = document.getElementById('costproject_rebudget_funds')
    if checkbox.checked
      $("#costproject_new").attr('checked', false)
      $("#costproject_rebudget").attr('checked', false)
      $("#rebudgetamount").show()
    else
      $("#rebudgetamount").hide()
      $("#costproject_rebudget_amount").val('')

I added the alert "hey" for troubleshooting. 我添加了alert "hey"以进行故障排除。 It is getting triggered. 它正在被触发。

You use jquery everywhere else except right at the checkbox = document.getElementById('costproject_rebudget_funds') line. 除了在checkbox = document.getElementById('costproject_rebudget_funds')行之外,都可以在其他任何地方使用jquery。 Why not get the element using jquery? 为什么不使用jquery获取元素? checkbox = $('#costproject_rebudget_funds').get(0) perhaps? 复选框= $('#costproject_rebudget_funds')。get(0)? Here is a post possibly talking about some of the issues you are having: How to do this using jQuery - document.getElementById("selectlist").value 这是一篇可能谈论您所遇到的问题的文章: 如何使用jQuery-document.getElementById(“ selectlist”)。value

Particularly note the second answer not the picked one. 特别注意第二个答案而不是选择的答案。

For your deprecation error i'm unsure because you aren't showing the preventDefault code. 对于您的弃用错误,我不确定,因为您没有显示preventDefault代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 空字符串传递给自定义js的getElementById() - Empty string passed to getElementById() on custom js 获取空字符串传递给getElementById()。 在Firefox中 - Getting Empty string passed to getElementById(). in firefox fancybox和响应式文件管理器中的图像预览不起作用(将空字符串传递给getElementById()。) - image preview in fancybox and responsive filemanager not work (Empty string passed to getElementById().) ASP.Net Web Api 2 jQuery,将空字符串传递给getelementbyId(); - ASP.Net Web Api 2 JQuery, Empty string passed to getelementbyId(); 找到警告源的最佳方法:传递给getElementById()的空字符串 - Best way to locate source of Warning: Empty string passed to getElementById() 在query.unobtrusive-ajax.js:16处将空字符串传递给getElementById() - Empty string passed to getElementById() at query.unobtrusive-ajax.js:16 javascript getElementById为null-由此传递的ID - javascript getElementById is null - Id passed by this javascript getElementById 并将其转换为字符串 - javascript getElementById and convert it to String Javascript getElementById返回字符串 - Javascript getElementById returning string 当元素是空文本框时,Javascript document.getElementById("id").value 返回 null 而不是空字符串 - Javascript document.getElementById("id").value returning null instead of empty string when the element is an empty text box
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM