Created
June 14, 2012 06:41
-
-
Save hrstt/2928433 to your computer and use it in GitHub Desktop.
select 要素 の操作(隠したりdisableにしたり
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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