Skip to content

Instantly share code, notes, and snippets.

@hrstt
Created June 14, 2012 06:41
Show Gist options
  • Save hrstt/2928433 to your computer and use it in GitHub Desktop.
Save hrstt/2928433 to your computer and use it in GitHub Desktop.
select 要素 の操作(隠したりdisableにしたり
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script>
$(function(){
var target = $("select#test");
/** 単純に操作不可にする方法
target.change(function() {
target.attr("disabled","disabled");
});
*/
// 選択要素を表示してselectを隠す
var selected_place = $("span#selected_value");
target.change(function() {
selected_place.text(target.children(":selected").val());
target.hide();
});
selected_place.click(function() {
$(this).hide();
target.show();
});
});
</script>
</head>
<body>
<form action="./">
<span id="selected_value"></span>
<select name="test" id="test">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment