简体   繁体   English

从下拉列表中选择一个项目

[英]Select an item from the drop-down list

Good morning. 早上好。 I can not select an item from the drop-down list. 我无法从下拉列表中选择一个项目。

下降

Did the following: 做了以下事情:

1) I entered the text 1)我输入了文字

WebBrowser1.Document.GetElementById ("Advert_category_id").InnerText = "Wedding / Event Services";

2) Set the value using the following commands, in different sequences, as soon as not twisted. 2)一旦扭曲,请使用以下命令以不同的顺序设置值。

WebBrowser1.Document.GetElementById("Advert_category_id").SetAttribute("selected", "selected");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember("onchange");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember("submit");
WebBrowser1.Document.GetElementById("Advert_category_id").InvokeMember ("value", "84");

The problem is that this code selects the option I need, but it does not appear in the field. 问题在于此代码选择了我需要的选项,但是它没有出现在字段中。 Those. 那些。 Only when you click on the field, after executing the code, you can see that the desired option is selected. 仅当您单击该字段时,在执行代码后,您才能看到已选择所需的选项。 But this approach is also not true, because The following drop-down list named SUB CATEGORY does not load the required data (the data remains with the category selected by default - Professional) 3. I tried to experiment with different id-shniki. 但是这种方法也不是正确的,因为以下名为SUB CATEGORY的下拉列表不会加载所需的数据(该数据保留默认情况下所选的类别-专业)。3.我尝试使用不同的id-shniki。 Nothing helps :( 没有任何帮助:(

The site itself https://list.asiandirectoryapp.com/advert/create (You must register to view) I made the second ack, That would not waste time for registration fovogaze@p33.org qwerty123 The code of interest 该网站本身https://list.asiandirectoryapp.com/advert/create (您必须注册才能查看)我做了第二个确认,这不会浪费注册时间fovogaze@p33.org qwerty123感兴趣的代码

  <div style="display:none"><div class="form-group"><label class="control-label" for="Advert_city_id">City</label><select class="form-control" name="Advert[city_id]" id="Advert_city_id"> </select><div class="help-block error" id="Advert_city_id_em_" style="display:none"></div></div></div><div class="form-group"><label class="control-label required" for="Advert_category_id">Category <span class="required">*</span></label><select class="form-control" name="Advert[category_id]" id="Advert_category_id"> <option value=""></option> <option value="35">Beauty, Health &amp; Fitness</option> <option value="19">Education</option> <option value="21">Entertainment</option> <option value="27">Food, Drink &amp; Sweet Centres</option> <option value="39">Home Services</option> <option value="116">Jobs/Careers</option> <option value="43">Motoring</option> <option value="50">Other Services</option> <option value="1">Professional</option> <option value="51">Property Improvements</option> <option value="84">Wedding/Event Services</option> <option value="117">Whats On Guide</option> </select><div class="help-block error" id="Advert_category_id_em_" style="display:none"></div></div><div class="form-group"><label class="control-label required" for="Advert_categoryList">Sub category <span class="required">*</span></label><select multiple="multiple" class="form-control" name="Advert[categoryList][]" id="Advert_categoryList"> <option value="2">Accountants</option> <option value="4">Claims</option> <option value="123">Clothing Manufacturers</option> <option value="6">Estate &amp; Letting Agents</option> <option value="7">Finance/Mortgages</option> <option value="8">Graphic &amp; Web Design</option> <option value="9">Immigration</option> <option value="10">Information Technology</option> <option value="11">Insurance</option> <option value="13">Mobile Apps - Mobile Phones</option> <option value="14">Online Marketing/ SEO</option> <option value="18">Print</option> <option value="15">Retail and Wholesale</option> <option value="16">Solicitors - Lawyers</option> <option value="17">Travel Agents</option> </select><div class="help-block error" id="Advert_categoryList_em_" style="display:none"></div></div><div class="form-group"><label class="control-label required" for="Advert_name">Company Name <span class="required">*</span></label><input class="form-control" placeholder="Company Name" name="Advert[name]" id="Advert_name" type="text" maxlength="100" /><div class="help-block error" id="Advert_name_em_" style="display:none"></div></div> 

PS I can fill out all the fields, press the buttons the same way, but with the drop-down list the trouble. PS我可以填写所有字段,以相同的方式按下按钮,但是使用下拉列表列出了麻烦。 Thank you for any help. 感谢您的任何帮助。

I had a similar problem but I chose to solve it by simply invoking a client-side javascript (with a parameter) that handles the manipulation of the dom objects. 我有一个类似的问题,但我选择通过简单地调用处理dom对象操作的客户端javascript(带有参数)来解决。

I found that this way I can separate code too, keeping dom handling in the JS and application-code in the winforms. 我发现通过这种方式我也可以分离代码,在JS中保留dom处理,在winforms中保留应用程序代码。 Itll also allow you to leverage any functionality provided by eg jQuery plugins wrapping the select. Itll还允许您利用包装选择的jQuery插件提供的任何功能。

It could look like this (not tested): 它可能看起来像这样(未经测试):

Object[] objArray = new Object[2];
        objArray[0] = selectorID;
        objArray[1] = valueToSet;
webBrowser1.Document.InvokeScript("SetSelector", objArray);

and in the client side: 在客户端:

function SetSelector(selectorID, valueToSet){
  $('#'+selectorID).val(valueToSet); //or any function you'd like
}

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

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