开发者

JavaScript or Qt way to update a select box value?

开发者 https://www.devze.com 2022-12-28 22:14 出处:网络
So I have the following HTML and am trying to change which item is selected. <select name=\"coolselectbox\">

So I have the following HTML and am trying to change which item is selected.

<select name="coolselectbox">
   <option value="default" selected="selected">---</option>
   <option value="something">Something</option>
   <option value="something-else">Something Else</option>
</select>

Here's what I've tried:

QWebElement defaultOpt = 
       this->page()->mainFrame()->findFirstElement("option[value=default]");

QWebelement somethingOpt = 
       this->page()->mainFrame()->findFirstElement("option[value=something]");

defaultOpt.removeAttribute("selected");
somethingOpt.setAttribute("selected", "selected");

And then also:

QWebElement selectBox = 
       this->page()->mainFrame()->findFirstElement("select[name=coolselectbox]");

selectBox.setAttribute("value", "something-else");

However neither of these seems to get the job done.

Does anyo开发者_StackOverflowne know a Qt solution, or is there perhaps some JavaScript snippet I can run to do this?


I think you should try jquery.
It will gave what are you looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消