drop-down-menu 相关问题

用户界面控件GUI元素,类似于列表框,允许用户从列表中选择一个值。当下拉列表处于非活动状态时,它会显示单个值。激活后,它会显示(下拉)一个值列表,用户可以从中选择一个值。

Slim-Select 插件在 Bootstrap 5.3 深色模式下无法正常工作

Slim-Select 插件不能很好地与 Bootstrap 5.3 深色模式配合使用,即使应用程序使用深色模式,该插件也会默认为浅色模式。这也会影响输入元素搜索框或搜索...

回答 1 投票 0


在 selenium webdriver 中使用 md-select 和 md-option 进行下拉选择

如何在 selenium webdriver 中使用 md-select 和 md-option 选择下拉列表。 选择不支持的类别。 如何在 selenium webdriver 中使用 md-select 和 md-option 选择下拉列表。 不支持选择班级。 <md-select placeholder="Filter" class="filter-select md-no-underline ng-pristine ng-valid ng-empty ng-touched" ng-model="$ctrl.dummy" aria-label="Filters" tabindex="0" aria-disabled="false" role="listbox" aria-expanded="false" aria-multiselectable="false" id="select_80" aria-invalid="false" style=""><md-select-value class="md-select-value md-select-placeholder" id="select_value_label_70"><span>Filter</span><span class="md-select-icon" aria-hidden="true"></span></md-select-value><div class="md-select-menu-container" aria-hidden="true" role="presentation" id="select_container_81"><md-select-menu role="presentation" class="_md"><md-content class="_md"> <!-- ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_93"><div class="md-text ng-binding"> Pending </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_94"><div class="md-text ng-binding"> Posted </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_95"><div class="md-text ng-binding"> Checks &amp; eChecks </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_96"><div class="md-text ng-binding"> Deposit </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --><md-option md-option-empty="" ng-repeat="filter in $ctrl.allFilters" ng-click="$ctrl.applyFilter(filter)" ng-keyup="$event.keyCode === 32 ? $ctrl.applyFilter(filter) : null" tabindex="0" class="ng-scope md-ink-ripple" role="option" aria-selected="false" id="select_option_97"><div class="md-text ng-binding"> Withdrawal </div></md-option><!-- end ngRepeat: filter in $ctrl.allFilters --> </md-content></md-select-menu></div></md-select> 假设您想从选项中选择Pending。你可以这样做: WebElement option = driver.findElement(By.id("select_option_93")); option.click(); 以下代码给出了来自selenium驱动程序的perfecto设备连接 import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import com.perfectomobile.selenium.api.IMobileDevice; import com.perfectomobile.selenium.api.IMobileDriver; import com.perfectomobile.selenium.api.IMobileWebDriver; import com.perfectomobile.selenium.params.analyze.text.MobileTextMatchMode; public class BofaApp_app extends PerfectoMobileBasicTest implements Runnable{ /* * * Class Name : PerfectoMobileBasicTest * Author : Uzi Eilon <[email protected]> * Date : Dec 6th 2013 * * Description : * Mobile Native application test * The test open the BOFA app (on a real device) and looks for an ATM. * This test contains IMobileWebDriver (extension to webdriver), which allows the to get native and visual objects on mobile app * */ public BofaApp_app(IMobileDriver driver) { super(driver); } @Override public void execTest() { IMobileDevice device = ((IMobileDriver) _driver).getDevice(_DeviceId); device.open(); device.home(); IMobileWebDriver webDriver = _driver.getDevice(_DeviceId).getVisualDriver(); webDriver.findElement(By.linkText("Bofa")).click(); IMobileWebDriver init = _driver.getDevice(_DeviceId).getVisualDriver(); init.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); init.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST); init.findElement(By.linkText("Account")).click(); webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); webDriver.findElement(By.linkText("Save this online")); webDriver.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST); webDriver.findElement(By.linkText("Locations")).click(); webDriver.findElement(By.linkText("Find Bank of America ATMs")); IMobileWebDriver zip = _driver.getDevice(_DeviceId).getVisualDriver(); zip.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST); zip.findElement(By.linkText("zip code")).click(); sleep(2000); zip.findElement(By.linkText("zip code")).click(); sleep(2000); webDriver.manageMobile().visualOptions().textMatchOptions().setMode(MobileTextMatchMode.LAST); webDriver.manageMobile().visualOptions().ocrOptions().setLevelsLow(120); webDriver.findElement(By.linkText("Code")).sendKeys("02459"); zip.findElement(By.linkText("Done")).click(); zip.findElement(By.linkText("Go")).click(); webDriver.findElement(By.linkText("Newton MA")); } }* public class Constants { /** Project Constants */ public static final String REPORT_LIB = "C:\\Test\\"; public static final String HTML_REPORT_NAME = "Total.html"; public static final String PM_USER = "[email protected]"; public static final String PM_PASSWORD = "*************"; public static final String PM_CLOUD = "prerelease.perfectomobile.com"; } public interface ExecutionReporter { /* * * Class Name : ExecutionReporter * Author : Uzi Eilon <[email protected]> * Date : Dec 6th 2013 * * Description : * Reporter allows you to build an summary report which aggregate all the executions the results and the link for the specific test report * You can find an HTML reporter in this project * */ public void reportHeader (String title); public void addLine(String testName,String deviceID,String repID,boolean status); public void closeRep(); } import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; /* * * Class Name : HTMLReporter * Author : Uzi Eilon <[email protected]> * Date : Dec 6th 2013 * * Description : * implements ExecutionReporter and create an HTML summary report * */ public class HTMLReporter implements ExecutionReporter { BufferedWriter _bw = null; public HTMLReporter (String title ) { reportHeader(title); } public void reportHeader (String title) { String repName = Constants.REPORT_LIB+ Constants.HTML_REPORT_NAME; File f = new File (repName) ; try { _bw = new BufferedWriter(new FileWriter(f)); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Calendar cal = Calendar.getInstance(); _bw.write("<p> Date :"+dateFormat.format(cal.getTime())+" </p>"); _bw.write("<p> Test Name: "+title+"</p>"); _bw.write("<p>"); _bw.write("<p>"); _bw.write("<table border=\"1\">"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void addLine(String testName,String deviceID,String repID,boolean status) { try { _bw.write("<tr>"); _bw.write("<td>"+testName+"</td>"); _bw.write("<td>"+deviceID+"</td>"); _bw.write("<td> <a href=\""+repID+"\">Report</a></td>"); _bw.write("<td>"+status+"</td>"); _bw.write("</tr>"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void closeRep() { try { _bw.write("</table></p></body></html>"); _bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } import java.lang.reflect.Constructor; import com.perfectomobile.selenium.*; import com.perfectomobile.selenium.api.*; public class MobileTest { /* * * Class Name : MobileTest * Author : Uzi Eilon <[email protected]> * Date : Dec 6th 2013 * * Description : * Mobile Executer gets list of test and devices and execute it on the available devices * in this example the list arrive form array [] [] * The tests run on real devices in Perfecto Mobile cloud */ public static void main(String[] args) { System.out.println("Script started"); String host = Constants.PM_CLOUD; String user = Constants.PM_USER; String password = Constants.PM_PASSWORD; String[] [] testcase ={ // {"PerfectoTestCheckFlight","3230D2D238BECF6D"}, // {"PerfectoTestCheckFlight","4A8203C8DBAB382EE6BB8021B825A736CA734484"}, {"BofaApp_app","4A8203C8DBAB382EE6BB8021B825A736CA734484"}, // {"usAirways","3230D2D238BECF6D"} }; ExecutionReporter reporter = new HTMLReporter("Regression Test Tesults"); try { for(int i =0; i < testcase.length; i++) { IMobileDriver driver = new MobileDriver(host, user, password); String className = testcase[i][0]; String device = testcase[i][1]; PerfectoMobileBasicTest test = null; Constructor con = null; try { con = Class.forName(className).getConstructor(IMobileDriver.class); } catch (ClassNotFoundException e) { e.printStackTrace(); } try { test = (PerfectoMobileBasicTest)con.newInstance(driver); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } //PerfectoMobileBasicTest test = new PerfectoTestCheckFlight(driver); test.setDeviceID(device); Thread t = new Thread(test); t.start(); reporter.addLine(className,device,test.getRepName(),test.getStatus()); } } catch (Exception e) { e.printStackTrace(); } finally { reporter.closeRep(); } } } import java.io.File; import java.io.InputStream; import com.perfectomobile.httpclient.MediaType; import com.perfectomobile.httpclient.utils.FileUtils; import com.perfectomobile.selenium.api.IMobileDriver; /* * * Class Name : PerfectoMobileBasicTest * Author : Uzi Eilon <[email protected]> * Date : Dec 6th 2013 * * Description : Basic abstract perfecto mobile test - Each test need to extend this class and implement the actual test in the PerfectoMobileBasicTest * This basic test handles the driver and the device */ public abstract class PerfectoMobileBasicTest implements Runnable{ String _DeviceId = null; IMobileDriver _driver; boolean _status = true; @Override public void run() { try { execTest(); }catch (Exception e) { _status = false; } closeTest(); getRep(MediaType.HTML); } public PerfectoMobileBasicTest (IMobileDriver driver) { _driver = driver; } public Boolean getStatus() { return _status ; } public void setDeviceID(String Device) { _DeviceId= Device; } public String getRepName() { String className = this.getClass().getName(); String name = Constants.REPORT_LIB+className+_DeviceId+".HTML"; return name; } public void getRep(MediaType Type) { InputStream reportStream = ((IMobileDriver) _driver).downloadReport(Type); if (reportStream != null) { File reportFile = new File(getRepName()); FileUtils.write(reportStream, reportFile); } } public void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { } } public void closeTest( ) { _driver.quit(); } public abstract void execTest() throws Exception ; }* import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import com.perfectomobile.selenium.api.IMobileDevice; import com.perfectomobile.selenium.api.IMobileDriver; import com.perfectomobile.selenium.api.IMobileWebDriver; /* * * Class Name : PerfectoTestCheckFlight * Author : Uzi Eilon <[email protected]> * Date : Dec 6th 2013 * * Description : * Mobile web test * the test go to united.com (on a real device) and check the status of flights number 84 * it use a web driver which connected to Perfecto Mobile cloud. * the test is based on a webDriver test */ public class PerfectoTestCheckFlight extends PerfectoMobileBasicTest implements Runnable{ public PerfectoTestCheckFlight(IMobileDriver driver) { super(driver); } @Override public void execTest() { IMobileDevice device = ((IMobileDriver) _driver).getDevice(_DeviceId); device.open(); device.home(); //device.getScreenText() //device.checkpointText("search"); WebDriver webDriver = device.getDOMDriver ("www.united.com"); webDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); webDriver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS); //sleep(2000); question? String url = webDriver.getCurrentUrl(); String title = webDriver.getTitle(); System.out.println("url: " + url + ", title: " + title); WebElement webElement = webDriver.findElement(By.xpath("(//#text)[53]")); webElement.click(); webElement = webDriver.findElement(By.xpath("(//@id=\"FlightNumber\")[1]")); webElement.sendKeys("84"); webDriver.findElement(By.xpath("(//INPUT)[5]")).click(); }* <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Supported Documents</title> <style> body { font-family: Arial, sans-serif; } .container { width: 80%; margin: auto; padding-top: 20px; } h1 { color: #333; } ul { list-style: none; padding: 0; } li { margin-bottom: 10px; } .alphabet-nav { position: fixed; top: 20px; right: 50px; background: #f7f7f7; padding: 10px; border-radius: 5px; } .alphabet-nav a { text-decoration: none; padding: 5px; display: inline-block; color: #007bff; } section { margin-top: 20px; } </style> </head> <body> <div class="container"> <h1>Full List of Supported Documents</h1> <div class="alphabet-nav"> <a href="#C">C</a> <a href="#I">I</a> <a href="#U">U</a> </div> <section> <h2>Canada 🇨🇦</h2> <ul> <li>Driver License</li> <li>Identification Card</li> <li>Passport</li> <li>Residence Permit</li> </ul> </section> <section> <h2>India 🇮🇳</h2> <ul> <li>Passport</li> </ul> </section> <section> <h2>United Kingdom 🇬🇧</h2> <ul> <li>Driver License</li> <li>Passport</li> <li>Residence Permit Card</li> </ul> </section> <section> <h2>United States 🇺🇸</h2> <ul> <li>Driver License</li> <li>Identification Card</li> <li>Passport</li> <li>Passport Card</li> <li>Permanent Resident Card</li> </ul> </section> </div> </body> </html>

回答 3 投票 0

CSS 绝对位置和父容器的宽度(以百分比表示)

我正在尝试构建一个宽度灵活的 HTML/CSS 下拉菜单。由于第二级导航的位置:绝对,我无法获得第一级的宽度。删除

回答 4 投票 0

插入数据验证

我正在尝试使用 Google Apps 脚本在 Gsheet 中插入单元格内下拉菜单(数据 > 验证 > 项目列表)。我想这样做是因为每次我使用电子表格时都会出现“项目列表...

回答 1 投票 0

Streamlit 选择框正在重置网页

我目前正在尝试使用选择框来允许用户选择用于运行模型的列的名称。当我在侧边栏中放置选择框时,我没有遇到问题,但是当我放置选择框时......

回答 2 投票 0

尝试直接在 div 下打开我的下拉菜单

我有一个带有一个下拉项的菜单。但是,我无法使其工作,因此它在关联的 div 项目下打开。 这是我的代码: 。落下 { 位置:相对; } .dropdown-内容{ 显示...

回答 1 投票 0

当我将鼠标移到导航栏上时,不会出现下拉菜单

美好的一天, 我试图在我的新网站上创建一个下拉菜单,但找不到它不出现的原因。 它应该出现在“关于”下,但当我点击它时却没有......

回答 1 投票 0

将我的下拉导航调整为与其父/按钮相同的大小

我一直在尝试创建一个个人网页。 它的顶部有一个导航栏,我最满意的是,除了我无法获得下拉导航框(使用事件侦听器通过 JS 控制)...

回答 1 投票 0

从日期数组中创建 <select> 选项并选择今天的日期或下一个未来日期

为什么这不起作用,它应该标记今天的日期或今天之后最近的日期。例如,如果日期是 16-01-30,则选择的日期将为 16-02-14。 $日期 = ['16-01-14', '16-01-28', '...

回答 1 投票 0

将下拉子菜单与其父标题对齐

我正在构建一个下拉菜单,但在尝试对齐 Sub-Menu-1 使其位于主菜单标题的中心时,我遇到了 CSS 问题。 看这张图片 我兜了一圈,唯一的...

回答 1 投票 0

购物车中每件商品的动态编辑表单

我希望用户能够编辑购物车中商品的数量,而无需打开新页面或对话框。购物车中显示的数量应变成下拉菜单,然后您...

回答 1 投票 0

如何从反应中的动态选择下拉列表中清除所选值?

我已经实现了一种表单,其中选择下拉列表从服务器获取动态数据。 现在,当我从下拉列表中选择一个选项时,它会在字段中显示值,但保存表单后或可以...

回答 2 投票 0

如何为Android菜单项添加行分隔线

我的菜单项变得更大,因此我想将它们分组并制作一个分隔线来分隔每个组。 我现在应该怎么做 ? 我的菜单项变得更大,因此我想将它们分组并制作一个分隔线来分隔每个组。 我现在该怎么办? <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <!--group1--> <item android:id="@+id/action_addtag" android:title="@string/add_hashtag_string" app:showAsAction="never" /> <item android:id="@+id/action_block_list" android:title="Block" app:showAsAction="never" /> <item android:id="@+id/action_report_list" android:title="Report" app:showAsAction="never" /> <!--group2--> <item android:id="@+id/terms" android:title="Terms" app:showAsAction="never" /> <item android:id="@+id/feedback" android:title="FeedBack" app:showAsAction="never" /> <!--group3--> <item android:id="@+id/action_setting" android:title="Setting" app:showAsAction="never" /> </menu> 膨胀菜单时请务必致电MenuCompat.setGroupDividerEnabled(menu, true);,否则组将不会被分隔线分开! 示例: @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_activity_main, menu); MenuCompat.setGroupDividerEnabled(menu, true); return true; } 并确保您的菜单 xml 中有不同的组,例如: <menu> <group android:id="@+id/sorting" > <item android:id="@+id/action_sorting_new_old" android:title="@string/action_sorting_new_old"/> <item android:id="@+id/action_sorting_a_z" android:title="@string/action_sorting_a_z"/> </group> <group android:id="@+id/settings"> <item android:id="@+id/action_settings" android:title="@string/action_settings"/> </group> </menu> 您需要做的就是定义一个具有唯一 ID 的组,我已经检查了实现,如果组具有不同的 id,它将创建一个分隔符。 示例菜单,创建分隔符: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <group android:id="@+id/grp1"> <item android:id="@+id/navigation_item_1" android:checked="true" android:icon="@drawable/ic_home" android:title="@string/navigation_item_1" /> </group> <group android:id="@+id/grp2"> <item android:id="@+id/navigation_item_2" android:icon="@drawable/ic_home" android:title="@string/navigation_item_2" /> </group> 希望这有帮助 更新 对于菜单项也许你可以使用这个 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <item android:id="@+id/action_cart" android:title="cart" android:actionLayout="@layout/cart_update_count" android:icon="@drawable/shape_notification" app:showAsAction="always"/> </menu> actionLayout 文件将是 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"> <View android:id="@+id/divider" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/divider"/> <TextView android:id="@android:id/text" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:textAppearance="?attr/textAppearanceListItemSmall"/> </LinearLayout> 老问题,但上述答案对我不起作用(并且我反对为单个项目添加“组”)。起作用的是添加一个样式元素,如下所示: <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> <!-- .Light.DarkActionBar"> --> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">#17161B</item> <item name="colorAccent">@color/colorAccent</item> <item name="android:dropDownListViewStyle">@style/PopupMenuListView</item>//<-add this </style> 参考文献 <style name="PopupMenuListView" parent="@style/Widget.AppCompat.ListView.DropDown"> <item name="android:divider">#dddddd</item> <item name="android:dividerHeight">1dp</item> </style> 在同一个 res/values/styles.xml 文件中。希望有帮助! 如果您需要在“溢出”菜单中添加垂直线(最右侧的省略号): 假设您已添加新的菜单资源文件,请执行以下操作。 对菜单项进行分组并为每个组分配唯一的 ID <group android:id="@+id/group1"> <item android:id="@+id/action_about" android:orderInCategory="100" android:title="@string/about" app:showAsAction="never" /> </group> <group android:id="@+id/group2"> <item android:id="@+id/action_settings" android:orderInCategory="200" android:title="@string/settings" app:showAsAction="never" /> </group> 当您在 Activity 的 oncreate 方法中膨胀菜单时: getMenuInflater().inflate(R.menu.main, menu);//inflate menu MenuCompat.setGroupDividerEnabled(menu, true);//add horizontal divider 对于 Android SDK 28+: 将具有 id (!) 的组添加到 xml 菜单文件中以进行分配。 <group android:id="@+id/id_0"> ... </group> 添加行代码。 @Override public boolean onCreateOptionsMenu(Menu menu) { ... menu.setGroupDividerEnabled( true ); // this line ... } 这对我来说非常有效... <item android:title="@string/divider" MetaJsoup:showAsAction="ifRoom|withText" /> <string name="divider">-------------</string>

回答 6 投票 0

不存在具有键“RouterElect”的“IEnumerable<SelectListItem>”类型的 ViewData 项

这个问题之前曾被问过类似的问题,但我不确定如何将这些答案应用于我的具体问题: 视图模型 公共字符串 RouterElect { 得到;放; } 看法 如果((!字符串。

回答 1 投票 0

React Native Expo 模式内的自定义下拉菜单未正确显示

我最近按照 YouTube 教程创建了一个自定义下拉组件(下面的代码片段)。 下拉菜单效果很好,但有一个我无法解决的大样式问题。 每当我...

回答 1 投票 0

Django:在模板中选择选项

在我的 Django 模板中,我使用下拉菜单中的对象列表。我正在根据选择对其进行处理。 HTML 模板: 在我的 Django 模板中,我使用下拉菜单中的对象列表。我正在根据选择进行处理。 HTML 模板: <select id="org" name="org_list" onChange="redirectUrl()"> <option value="" selected="selected">---SELECT---</option> {% for org in organisation %} <option value="{{org.id}}">{{org.name|capfirst}}</option> {% endfor %} </select> 问题是,当我从下拉菜单中选择值时,我得到了属于所选内容的内容。由于属性 selected="selected" 仅修复到 "---SELECT---" 元素,除非我将 selected="selected" 放入 <option value="{{org.id}}" selected="selected">{{org.name|capfirst}}</option> 在这些组织中,最后一个迭代元素仅通过下拉菜单进行固定。但我希望所选元素显示在下拉菜单中。 如何解决这个问题? 您需要将当前选定的组织传递到视图中,可能为 current_org,这样当您迭代组织时,您可以与当前组织进行比较以确定是否选择它,例如: {% for org in organisation %} <option value="{{org.id}}" {% if org == current_org %}selected="selected"{% endif %}> {{org.name|capfirst}} </option> {% endfor %} 最近我找到了解决这个问题的更好方法,我在 django 论坛 上分享了 在此再次重申: {% for option in form.form_field.subwidgets %} <option value="{{ option.data.value }}" {{option.data.attrs.selected|safe|yesno:"selected,"}}> {{ option.choice_label }} </option> {% endfor %}

回答 0 投票 0

如何将值从下拉菜单中的可用部分移动到选定部分

在 Selenium WebDriver 中使用 selectByVisibleText() 方法时,它会正确突出显示下拉列表中所需的选项,但不会从“可用值”秒中移动所选值...

回答 1 投票 0

从动态创建的下拉菜单更新当前下拉值时出现问题

我在读取 JavaScript 中动态创建的下拉列表的值时遇到问题。我调用函数 addElement_Tract(),它是创建下拉列表的函数,并读取当前的...

回答 1 投票 0

占位符不适用于有角度的材质?

<select id="chefId" formControlName="chefId" class="form-control" placeholder="d.ff"> <option value="" selected disabled>Sélectionner un Chef</option> <option *ngFor="let buHead of buHeads" [value]="buHead.userId">{{ buHead.name }}</option> </select> 我想给 ChefId 一个占位符 (https://i.sstatic.net/Z9DCN3mS.png) this.addUserForm = this.formBuilder.group({ name: ['', Validators.required], email: ['', [Validators.required, Validators.email]], password: ['', Validators.required], confirmPassword: ['', Validators.required], role: ['', Validators.required], chefId: [''], }); In Angular Material, placeholders for <select> elements are handled differently compared to regular HTML. The placeholder attribute doesn't work directly on <select> elements. Instead, you need to use Angular Material's <mat-select> component, which supports placeholders natively. Here's how you can achieve this using Angular Material's `<mat-select>`: 1.Install Angular Material (if not already installed): ng add @angular/material 2.Import MatSelectModule in your app module: import { MatSelectModule } from '@angular/material/select'; @NgModule({ ... imports: [ ... MatSelectModule, ... ], ... }) export class AppModule { } 3. Update your template to use <mat-form-field> and <mat-select>: <mat-form-field appearance="fill"> <mat-label>Sélectionner un Chef</mat-label> <mat-select id="chefId" formControlName="chefId"> <mat-option value="" disabled>Sélectionner un Chef</mat-option> <mat-option *ngFor="let buHead of buHeads" [value]="buHead.userId">{{ buHead.name }}</mat-option> </mat-select> </mat-form-field> Here, <mat-form-field> is a container for form elements, and <mat-label> serves as a label for the field. The placeholder text "Sélectionner un Chef" is displayed by default when no option is selected. 4.Ensure your form is properly defined in the component: import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-your-component', templateUrl: './your-component.component.html', styleUrls: ['./your-component.component.css'] }) export class YourComponent implements OnInit { addUserForm: FormGroup; buHeads = [ { userId: '1', name: 'Chef One' }, { userId: '2', name: 'Chef Two' } // Add more chef objects here ]; constructor(private formBuilder: FormBuilder) {} ngOnInit(): void { this.addUserForm = this.formBuilder.group({ name: ['', Validators.required], email: ['', [Validators.required, Validators.email]], password: ['', Validators.required], confirmPassword: ['', Validators.required], role: ['', Validators.required], chefId: ['', Validators.required] }); } }

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.