Home > Web Front-end > JS Tutorial > jquery selects the option instance code under select based on a value

jquery selects the option instance code under select based on a value

高洛峰
Release: 2017-01-03 16:53:43
Original
997 people have browsed it

How does jquery select the option under select based on a value

<script type="text/javascript">
$(document).ready(function(){
  var str="";
  str = &#39;${conclusionTypeName}&#39;;
  $("#firstName option").each(function(){
    alert($(this).text());
    if($(this).text() == str){
    $(this).attr("selected",true);
    }
  });   
});
 
</script>
Copy after login

Note: The red mark code represents a Chinese string passed from Action to the page (conclusionTypeName must be defined as global Variable, this expression can avoid the problem of Chinese garbled characters, and there is no need to transcode in Action)

<s:select id="firstName" name="id" list="nodeList" listKey="id" listValue="name" onchange="send()" headerKey="0" headerValue="---请选择结论词类型---" /><br/>
Copy after login

The above jquery example code to select the option under select based on a value is shared by the editor I’ve given you all the content, I hope it can give you a reference, and I hope you will support the PHP Chinese website.

For more jquery to select the option instance code under select based on a value, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template