Jquery下拉列表添加移除数据
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="file:///E|/课程视频/0103Jquery/Jquery/jquery-1.11.2.min.js"></script> </head> <body> <select id="sel"> </select> <input type="text" id="shuru" /> <input type="button" value="添加" id="btn" /> <input type="button" value="移除" id="yichu" /> </body> <script type="text/javascript"> $("#btn").click(function(){ var v = $("#shuru").val(); //var str = "<option value='"+v+"'>"+v+"</option>"; //造元素 var op = document.createElement("option"); op.setAttribute("value",v); op.innerHTML = v; $("#sel").append(op); //追加 }) $("#yichu").click(function(){ var v = $("#shuru").val(); $("[value='"+v+"']").remove(); //移除 }) </script> </html>