いつもお世話になっております。
本日はjavascript外部ファイル化についてです。
コードを内部と外部で作成しましたが、どこが間違っているのかわかりません。
どなたかご教授頂けないでしょうか?
(現状はjs部分の機能はエラーが返ってきます。)
内部コードは以下です。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
@import url("style.css") ;
</style>
<script type="text/javascript" src="script.js"></script>
<!-- 数値の連結 -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(function(){
$('input[type=button]').click(function(){
if ($('#text').val().length < 4) {
$('#text').val($('#text').val() + $(this).val());
}
});
});
</script>
</head>
<!-- キーボード入力不可 -->
<body onkeydown="return false;">
<div id="Numtitle">暗証番号を入力してください。</div>
<form method ="post"name="Form" onSubmit="return chValie()" action="BalanceInquiry2(DB).jsp">
<div id="title">暗証番号:<input type="text" id="text" name="pass" value="" onfocus="color1(this);"onblur="color2(this);" tabindex="1" title="4桁の暗証番号を入力してください。" ></div><br>
<br><table>
<div>
<tr>
<td><input type="button" value="7" id="7" tabindex="2" class="num-button" ></td>
<td><input type="button" value="8" id="8" tabindex="3" class="num-button" ></td>
<td><input type="button" value="9" id="9" tabindex="4" class="num-button" ></td>
</tr>
<tr>
<td><input type="button" value="4" id="4" tabindex="5" class="num-button" ></td>
<td><input type="button" value="5" id="5" tabindex="6"class="num-button" ></td>
<td><input type="button" value="6" id="6" tabindex="7" class="num-button" ></td>
</tr>
<tr>
<td><input type="button" value="1" id="1" tabindex="8" class="num-button" ></td>
<td><input type="button" value="2" id="2" tabindex="9" class="num-button" ></td>
<td><input type="button" value="3" id="3" tabindex="10" class="num-button" ></td>
</tr>
<tr>
<td colspan="3"><input type="button" value="0" tabindex="11" name="zero"class="num-button"></td>
</tr>
</div>
</table>
</div>
<div id="menu">
<table border="1">
<tr>
<td width="33.3%;"><input type="submit" value="戻る" class="button" name="Back" tabindex="12"onclick="history.back()"></td>
<td width="33.3%;"><input type="reset" value="訂正" class="button" name="Correction" tabindex="13"></td>
<td width="33.3%;"><input type="submit" value="確認" class="button" name="Check" tabindex="14"></td>
<td width="33.3%;"><input type="submit" value="メインメニュー"class="button" name="Back" tabindex="15" onclick="location.href='Mainmenu.jsp'"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
外部ファイルは以下です。
function color1(text) {
text.style.background ="#F5F5F5";
}
function color2(text) {
text.style.backgroundColor = "#D7EEFF";
}
function chValie() {
TextCheck = new Array("pass");
TextCheck_nm= new Array("暗証番号");
var result = confirm("こちらの"+TextCheck_nm+"でよろしいですか?");
for(i=0; i<TextCheck.length; i++) {
txt = document.Form.elements[TextCheck[i]].value;
if(txt == ""){
alert(TextCheck_nm[i]+"は必須項目です。");
location.href='BalanceInquiry2.jsp';
return false;
}
}
return true;
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/01 10:45