首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用胸腺叶模糊/onblur事件调用函数?

如何使用胸腺叶模糊/onblur事件调用函数?
EN

Stack Overflow用户
提问于 2020-04-22 19:16:45
回答 1查看 418关注 0票数 0

下面是我的HTML和Javascript。我正在使用thymeleaf.All,我想在这个select标签上执行模糊操作,即模糊警告用户选择的值。

代码语言:javascript
运行
复制
$(document).ready(function(){
alert("called");
  });
});

function addSubject(){
      var x = document.getElementById("sub").value;
      alert(x);
}
代码语言:javascript
运行
复制
<body>
    <div class="form-group" style="margin-top: 10px;">
       <label th:text="'Subject'"></label>
          <select class="form-control" id="sub" th:onblur="'addSubject()'">
          <option value="" th:disabled="disabled" th:selected="selected" th:text="'Select Subject'"></option>
                  <option th:text="'Add New Subject'" th:value="addSub"></option>
                  <option th:each="freesub : ${detailsofexams}"
                          th:text="${#strings.capitalize(freesub)}"
                          th:value="${#strings.toUpperCase(freesub)}">
                  </option>
                </select>
              </div>
<script
  th:src="@{${@mvcResourceUrlProvider.getForLookupPath('/admin/dist/js/freecontent.js')}}"></script>

</body>

EN

回答 1

Stack Overflow用户

发布于 2020-04-22 22:33:53

他们是我的JS文件中的拼写错误,正如@Simon先生在第一条评论中所建议的那样,在这样做之后,我的代码开始工作。下面是正确的代码

代码语言:javascript
运行
复制
$(document).ready(function(){
alert("called");
  });

function addSubject(){
  alert("x");
}
代码语言:javascript
运行
复制
<div class="form-group" style="margin-top: 10px;">
            <label th:text="'Subject'"></label>
            <select class="form-control" id="sub" th:onblur="'addSubject()'">
              <option value="" th:disabled="disabled" th:selected="selected" th:text="'Select Subject'"></option>
              <option th:text="'Add New Subject'" th:value="addSub"></option>
              <option th:each="freesub : ${detailsofexams}"
                      th:text="${#strings.capitalize(freesub)}"
                      th:value="${#strings.toUpperCase(freesub)}">
              </option>
            </select>
          </div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61363783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档