【发布时间】:2014-06-27 09:05:28
【问题描述】:
我有下一个字符串变量,其中包含下一个字符串
var content = '<div id="TypeModifiedProduct" class="form-group WSUage2">
<label for="TypeModified">Type</label>
<span class="pull-right alignText" style="margin-right: 40%;">
<input type="checkbox" id="UseTypeModified" name="UseTypeModified" > Use option
</span>
<select name="TypeModified" id="TypeModified" class="form-control" style="width:40%" >
<option value="Maintenance - Stand Alone form" >Maintenance - Stand Alone form</option>
<option value="Maintenance Plus - Stand Alone form">Maintenance Plus - Stand Alone form</option>
</select>
</div>';
现在我想搜索第二个选项
<option value="Maintenance Plus - Stand Alone form">Maintenance Plus - Stand Alone form</option>
并将其更改为已选择的选项
<option value="Maintenance Plus - Stand Alone form" selected >Maintenance Plus - Stand Alone form</option>
然后最后返回这个带有选项元素变化的新字符串。
感谢您的建议
【问题讨论】:
-
试试
var $div = $('<div />',{html: content}); $div.find('option[value="Maintenance Plus - Stand Alone form"]').attr('selected', 'selected'); content = $div.html()
标签: jquery html search replace