【问题标题】:Jquery selector for thymeleaf百里香叶的 Jquery 选择器
【发布时间】:2020-10-31 21:46:38
【问题描述】:

如何从下面div 内的隐藏字段中获取价值:

<div class="col-lg-6" th:each="devicedit : ${eachdevicedetails}">
  <div class="courses-container">
    <div class="course">
      <div
        class="course-preview"
        th:style="${devicedit.color} == 'Green' ? 'background: #03CB61' : 'background: #F22A54'"
      >
        <input type="hidden" name="hiddenDiviceId" th:value="${devicedit.id}" />
        <h6 th:text="${devicedit.area}"></h6>
        <h2 th:text="${devicedit.country}"></h2>
        <br /><br />
        <h6 th:text="${devicedit.state}"></h6>
      </div>
      <div class="course-info">
        <div class="progress-container">
          Status :
          <span
            class="badge badge-pill badge-success"
            th:style="${devicedit.color} == 'Green' ? 'background: #03CB61' : 'background: #F22A54'"
            th:text="${devicedit.color} == 'Green' ? 'Active' : 'Inactive'"
          ></span>
        </div>
        LastUpdate :
        <h6 th:text="${devicedit.lastupdatedon}"></h6>
        <h2 th:text="${devicedit.device_Name}"></h2>
        <br />
        <button
          onclick="openModal(this)"
          id="pickerMaster"
          class="btn btn-primary"
        >
          Detail View
        </button>
      </div>
    </div>
  </div>
</div>

我使用下面的jquery 代码来获取价值,但我只能选择 1st div:

$("#pickerMaster").click(function () {
  var divid = $(this)
    .closest("div.course")
    .find("input[name='hiddenDiviceId']")
    .val();
  console.log(divid);
});

【问题讨论】:

    标签: html jquery spring-boot thymeleaf hidden-field


    【解决方案1】:

    为此,您应该为 button 设置 class 并使用它来获取输入值:

    <button onclick="openModal(this)" class="btn btn-primary pickerMaster">Detail View</button>
    

    和:

    $(".pickerMaster").click(function() {
    var divid = $(this).closest("div.course").find("input[name='hiddenDiviceId']").val();
    console.log(divid);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 2016-08-14
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多