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

高洛峰
高洛峰Original
2017-01-03 16:53:431035browse

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>

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/>

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!


Statement:
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