Quantcast
Channel: ちょっとマティ~ニ »備忘録
Viewing all articles
Browse latest Browse all 3

selectタグonchangeイベント処理をjQueryで書き換える(置換する)。

$
0
0

元々ある処理を、書き換えるという状況になるのが間違っているのですが、、、^^;
やむを得ず、今回の方法をとりました。。

下記はそのサンプルコードになります。
selectタグのonchangeに指定された関数test1()の処理をjQueryので書き換えてます。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
<title>Insert title here</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", "1.6");</script>
<script type="text/javascript"><!--
function test1() {
	alert('test1');
}

jQuery(document).ready(
	function(){
		jQuery('select').attr('onchange', '');
		jQuery('select').change(function(){
			alert(jQuery('option:selected').val());
		});
	}
);

--></script>
</head>
<body>
	<form action="" name="frm">
		<select onchange="test1();">
			<option>aaa</option>
			<option>bbb</option>
			<option>ccc</option>
		</select>
	</form>
</body>
</html>

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images