简体   繁体   English

使用jQuery选择列表值更改,但不会在UI中显示

[英]Select list value change using jQuery but does not shows in UI

Hy everyone, I get a problem when changing select list option in jQuery, everything is working fine outside this theme. 大家好,在jQuery中更改选择列表选项时遇到问题,在此主题之外,一切工作正常。 when I create the select list in this theme it is changing select list like. 当我在此主题中创建选择列表时,它正在更改选择列表。 theme name is developr 主题名称是开发者

My code : 我的代码:

<select id="PackageID" name="PackageID" class="validate[required] withClearFunctions" style="width:200px" >
  <option value="">Please select</option>
  <option value="1">100 paper</option>
  <option value="2">500 paper</option>
</select>

What I got after rander 我追随兰德的经历

<span class="drop-down custom-scroll">
  <span class="selected">Please select</span>
  <span>100 paper</span>
  <span>500 paper</span>
  <div class="custom-vscrollbar" style="display: none;"><div></div></div>                           
</span>

when I change option in jQuery html changes but UI does not change. 当我更改jQuery html中的选项时,UI不会更改。

Code after selecting select list 选择列表后的代码

<span class="drop-down custom-scroll">
  <span>Please select</span>
  <span class="selected">100 paper</span>
  <span>500 paper</span>
  <div class="custom-vscrollbar" style="display: none;"><div>
</span>

I solve the problem. 我解决了问题。 I just firing the change event using jQuery 我只是使用jQuery触发change事件

$('#PackageID').change();

this event update UI. 此事件更新用户界面。

There are several ways to set option without a select drop down. 没有选择下拉菜单的设置方法有多种。 See fiddle for the most terse/readable option 有关最简洁/易读的选项,请参见小提琴

JSFiddle 的jsfiddle

Option 1: 选项1:

$('#PackageID').val('2'); 

Option 2 - via index: 选项2-通过索引:

$('#PackageID :nth-child(1)').prop('selected', true);

Option 3 - via value: 选项3-通过值:

$('#PackageID option:eq(2)').prop('selected', true);

All will update DOM and therefore render correctly. 全部都会更新DOM,因此可以正确呈现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM