Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created October 22, 2012 08:20
Show Gist options
  • Save masaru-b-cl/3930289 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/3930289 to your computer and use it in GitHub Desktop.
jQueryでselect要素入れ替えのサンプル
<!-- saved from url=(0014)about:internet -->
<!-- the comment above allows the embedded browser to load the document without the ActiveX security prompt -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jQueryPad Preview</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<style type="text/css">
body
{
font-family: Segoe UI;
font-size: 10pt;
background: white;
}
</style>
<script type="text/javascript">
$(document).ready(
function() {
$("#post").click(function(){
var list = $("#target");
list.empty();
list.append($("<option />"));
var result = eval("[{meetingRoomId:1, meetingRoomName: \"会議室1\"}, {meetingRoomId:2, meetingRoomName: \"会議室2\"}]");
$(result).each(function(index){
var item = result[index];
list.append(
$("<option />")
.val(item.meetingRoomId)
.text(item.meetingRoomName)
);
});
});
});
</script>
</head>
<body>
<div>
<select id="target">
<option value=""></option>
<option value="1">hoge</option>
<option value="2">fuga</option>
<option value="3">piyo</option>
</select>
</div>
<input type="button" id="post" value="Push" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment