Home >Web Front-end >JS Tutorial >JQuery uses attr method to implement drop-down list selection_jquery

JQuery uses attr method to implement drop-down list selection_jquery

WBOY
WBOYOriginal
2016-05-16 16:34:13879browse

The html code is as follows:

<select id="category" name="category">
<option value="">请选择类别</option>
<option value="1">类别1</option>
<option value="2">类别2</option>
<option value="3">类别3</option>
<option value="4">类别4</option>
</select>

js code:

<script type="text/javascript">
$('#category option[value=3]').attr('selected',true);
</script>
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