【问题标题】:Check if text includes a specific value in text area检查文本是否包含文本区域中的特定值
【发布时间】:2022-11-26 18:44:54
【问题描述】:

我有一个 JS,我可以在其中验证是否正在输入值并警告用户更改输入。 仅当该值存在于文本中并且该值与其他文本不起作用时,该脚本才能正常工作。

$(function() {
  const setup = function(fieldSelector) {
    const field = $(fieldSelector);
    const applyStyle = function() {
      if (field.val() == 'urgent') 
      {
        alert("Text not allowed!");
        field.css({'background-color': 'red'});
      } else {
        field.css({'background-color': ''});
      }
    };
    field.on('change', applyStyle);
    applyStyle();
  }
  // Note: Change the ID according to the custom field you want to target.
  setup('#issue_custom_field_values_17');
});

此代码在 redmine 问题跟踪器下。 任何指导将不胜感激

【问题讨论】:

    标签: javascript redmine redmine-plugins


    【解决方案1】:

    我对 jQuery 很陌生,但你不能直接替换

    if (field.val() == 'urgent')
    

    if (field.val().includes('urgent'))
    

    甚至

    if (field.val().indexOf('urgent')>-1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 2018-09-19
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多