选中文本框中的部分内容 然后用下拉框选值去替换

<script type="text/javascript">
function al(){
if(document.all)

    var content = document.selection.createRange(); 
}
else

    var  content = document.getElementById("ad").getSelection(); 
    content.text = content.toString(); 


   var select = document.getElementById("xuan");
    var index = select.selectedIndex;
    var xuanzhong = select.options[index].text;

var str = content.text;//选择的内容
content.text=xuanzhong;

}
</script>

<input id="ad" value="1234ABCDEFG456 ">
<select name="user" onChange="al()" id="xuan">
    <option value="1001">多云</option>
    <option value="1002">晴</option>
    <option value="1003" selected>小雨</option>
    <option value="1004">大雨</option>

你可能感兴趣的:(function,user)