我要根据自定义属性标记为已选中。
我的选择代码:
pc.createAnswer(function(answer) {
sdp = answer.sdp;
changedsdp = updateCodec(sdp) //Function to modify the sdp
answer.sdp = changedsdp
pc.setLocalDescription(answer)
在这里,我要标记为<select name="user_country" class="form-control" required="" data-error="Select Your Country" id="user_country">
<option data-iso2="in" value="1">India</option>
<option data-iso2="al" value="2">Albania</option>
<option data-iso2="dz" value="3">Algeria</option>
</select>
选中的
类似这样的东西:
data-iso2
在这里我要选择选项,其中var iso2 = 'in';
$('#user_country attr[data-iso2=iso2]').attr('selected','selected');
答案 0 :(得分:1)
您需要从option
值中找到要选择的data-iso2
:
var selVal = 'al';
$('#user_country').find('[data-iso2='+selVal+']').attr('selected','selected');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="user_country" class="form-control" required="" data-error="Select Your Country" id="user_country">
<option data-iso2="af" value="1">Afghanistan</option>
<option data-iso2="al" value="2">Albania</option>
<option data-iso2="dz" value="3">Algeria</option>
</select>