如何使用jQuery以编辑表单以编辑形式获取下拉值?

发布于 2025-01-22 16:55:54 字数 1975 浏览 0 评论 0原文

我有一个列表的表格,当我将数据添加到数据库时。当我单击“编辑”时,我可以获取所有其他字段的值,但是下拉列表并未显示以前在下拉列表中添加的值,请有帮助吗?

我正在尝试使用jQuery来做到这一点,

我正在使用Smantic进行jsp和Servlet作为后端和Postgres中的数据库的frontent,

这是我尝试的,但它只是在语义行为上找到了这一点,但它仅将值设置为默认值

$("#iddropdown").dropdown('set selected', ['fruits']);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js" integrity="sha512-dqw6X88iGgZlTsONxZK9ePmJEFrmHwpuMrsUChjAw1mRUhUITE5QU9pkcSox+ynfLhL15Sv2al5A0LVyDCmtUw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" integrity="sha512-8bHTC73gkZ7rZ7vpqUQThUDhqcNFyYi2xgDgPDHc+GXVGHXq+xPjynxIopALmOPqzo9JZj0k6OqqewdGO3EsrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="eight wide field">
  <label> Product Category </label>
  <select id="iddropdown" class="ui dropdown" name="category">
    <option value="category"> Category </option>
    <option value="fruits"> Fruits </option>
    <option value="vegetables"> Vegetables </option>
    <option value="rice"> Rice </option>
    <option value="flour"> Flour </option>
    <option value="snacks"> Snacks </option>
    <option value="beverages"> Beverages </option>
    <option value="sauces"> Sauces </option>
    <option value="cereal"> Cereal </option>
    <option value="spices"> Spices </option>
    <option value="pulses"> Pulses </option>
    <option value="cheese"> Cheese </option>
  </select>
</div>

I have a form with dropdown in it and when I am adding the data it is going to database. When I click on edit I can fetch the values of all other fields but the drop down is not showing the value which was added previously in the dropdown can some one please help ??

I am trying to do this with jquery ,

I am using semantic for frontend with jsp and servlet for the backend and database in postgres

this is what i have tried found this on semantic behavior but its only setting the value as default

$("#iddropdown").dropdown('set selected', ['fruits']);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js" integrity="sha512-dqw6X88iGgZlTsONxZK9ePmJEFrmHwpuMrsUChjAw1mRUhUITE5QU9pkcSox+ynfLhL15Sv2al5A0LVyDCmtUw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css" integrity="sha512-8bHTC73gkZ7rZ7vpqUQThUDhqcNFyYi2xgDgPDHc+GXVGHXq+xPjynxIopALmOPqzo9JZj0k6OqqewdGO3EsrQ==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="eight wide field">
  <label> Product Category </label>
  <select id="iddropdown" class="ui dropdown" name="category">
    <option value="category"> Category </option>
    <option value="fruits"> Fruits </option>
    <option value="vegetables"> Vegetables </option>
    <option value="rice"> Rice </option>
    <option value="flour"> Flour </option>
    <option value="snacks"> Snacks </option>
    <option value="beverages"> Beverages </option>
    <option value="sauces"> Sauces </option>
    <option value="cereal"> Cereal </option>
    <option value="spices"> Spices </option>
    <option value="pulses"> Pulses </option>
    <option value="cheese"> Cheese </option>
  </select>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˇ宁静的妩媚 2025-01-29 16:55:54
$("#iddropdown").dropdown('set selected', ['${product.category}'] );

最后,这对我有用!

$("#iddropdown").dropdown('set selected', ['${product.category}'] );

Finally this worked for me !!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文