【问题标题】:Rails, How to hide/show button, if multiple textbox are empty? [closed]Rails,如果多个文本框为空,如何隐藏/显示按钮? [关闭]
【发布时间】:2020-12-08 19:13:50
【问题描述】:
<%= text_field_tag :price, params[:price],class: "form-control pricee",id: "price",:maxlength => 4,:required => true %>
<%= text_field_tag :mobile, params[:mobile],class: "form-control mobilee",id: "mobile",:maxlength => 10,:required => true %>
<%= submit_tag "add", class: "btn btn-sm btn-primary form_submit" %>

如果文本字段为空,我会遇到问题隐藏/显示按钮。我对在 js 中使用两个文本字段的 id 有点困惑。

【问题讨论】:

  • 你尝试过什么,你在哪里卡住了?

标签: javascript jquery ruby-on-rails


【解决方案1】:

在 jQuery 中它应该是(如果你想让它在打字时工作):

$('[type="text"]').keypress(function(){
    if( $('[name="textbox1"]').val() || $('[name="textbox2"]').val() )
        $('[name="buttonExecute"]').show()
    else
        $('[name="buttonExecute"]').hide()
})

请注意,按钮隐藏“如果两个文本为空”。另外我认为您应该将按钮更改为:

<button id="buttonExecute" type="button">Execute</button>

.. 或类似的东西。

【讨论】:

  • 它在正常的 html 代码中工作,很抱歉,我想在 rails 中执行。
猜你喜欢
  • 2016-03-06
  • 1970-01-01
  • 2014-05-03
  • 2019-11-22
  • 2021-11-27
  • 1970-01-01
  • 1970-01-01
  • 2018-09-21
  • 1970-01-01
相关资源
最近更新 更多