IOS-在select-options下拉框中,动态修改默认值时,attr不支持,需要用prop解决

问题:在select下拉框动态修改默认值时,ios不支持attr,需要用prop

示例:1    直接选中默认值

<select>
	<option>0</option>
	<option>1</option>
	<option selected="selected">2</option>
	<option>3</option>
	<option>4</option>
	<option>5</option>
</select>

 

示例:2     动态修改默认值

<select>
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</select>
<script>
    $("select option:nth-of-type(5)").attr("selected","selected")
</script>

//此时,默认显示的是4(安卓,pc端正常,ios不正常)

  解决办法是:将attr换成prop

  

令我愤怒又疑惑的是,我现在为什么用attr时,ios又能正常操作了呢?kao 

posted @ 2021-01-15 11:43  MiniDuck  阅读(289)  评论(0编辑  收藏  举报