Code:
<tr>
<th>空间性质</th>
<td>
<input type="hidden" id = "class" value="{$post.post_class}"/>
<select class="form-control" name="post[post_class]" id="class2" value="{$post.post_class}">
<option value="0" id="op1">出售</option>
<option value="1" id="op2">出租</option>
</select>
</td>
</tr>
Display different option values according to the value of value={$post.post_class}
, value only has two values 0 and 1. TKS
The default selection is right, just use jquery's attr. Assuming that the default selection value is 1, the code is as follows:
Isn’t it enough to just set the value in the select tag to 0 or 1?
http://jsrun.net/d9YKp
Due to:
document.querySelector('#class').value
The value in select cannot be obtained (i.e.<select class="form-control" name="post[post_class]" id="class2" value="{$post.post_class}">
).So add a hidden input
<input type="hidden" id = "class" value="{$post.post_class}"/>
to get the value sent from the background, and then judge.