Google
 
Web itpro-blogger.blogspot.com
金曜日, 12月 18, 2009

[JavaScript]引数が無効です。

▼質問
「div.style.left」「div.style.top」で次のエラーが出る。

「引数が無効です。」

どうしてか教えて!

▼回答
div.style.left = left + "px";
div.style.top = top + "px";

leftとtopの値に数値じゃなくてNaNになっていると出るエラーみたい。

NaNのチェックが要るのね。

と言うことで、JavaScriptでは

isNaN( 文字列または数値 )関数でチェックする必要があるのね。


火曜日, 12月 15, 2009

[JavaScript]selectタグでのelements.type名

▼質問
elementsのtype名でselectタグをselectでチェックしようとしたんだけど

うまくいかなかったんだ。どうしてか教えてくれ!

▼回答
selectタグのtype名は、「select-one」か「select-multiple」なんだ。

他と違うから、気をつけてくれ!




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">

<script Language="javascript">
<!--

function testType()
{

with ( document.testForm ) {
for ( var i = 0 ; i < elements.length ; i++ ) {
alert( elements[i].type );
}
}

}

-->
</script>
<title></title>
</head>
<body>
<form name="testForm" method="post">

<input type="button" id="testButton" name="testButton" value="Type名称" onClick="testType();">

<input type="checkbox" id="testCheckbox" name="testCheckbox" value="testCheckbox">
<input type="file" id="testFile" name="testFile" value="testFile">
<input type="hidden" id="testHidden" name="testHidden" value="testHidden">
<input type="password" id="testPassword" name="testPassword" value="testPassword">
<input type="radio" id="testRadio" name="testRadio" value="testRadio">
<input type="reset" id="testReset" name="testReset" value="testReset">
<select id="testSelectOne" name="testSelectOne"><option value="テスト1">テスト1</option><option value="テスト2">テスト2</option><option value="テスト3">テスト3</option></select>
<select id="testSelectMultiple" name="testSelectMultiple" Multiple><option value="テスト1">テスト1</option><option value="テスト2">テスト2</option><option value="テスト3">テスト3</option></select>
<input type="submit" id="testSubmit" name="testSubmit" value="testSubmit">
<input type="text" id="testText" name="testText" value="testText">
<textarea id="testTextarea" name="testTextarea" rows="5" cols="10">テスト</textarea>

</form>

</body>
</html>




土曜日, 12月 12, 2009

[HTML]bodyタグの○○margin(余白)

▼質問
body要素にあるマージン(余白)のデフォルト値っていくつなの?

▼回答
IE(Internet Explorer)とNN(Netscape Navigator)では違うマージンとなっている。
IE:上下10px、左右15px
NN:上下左右8px

■参考サイト
ページの余白を指定する


金曜日, 12月 04, 2009

[JavaScript]HTML内の文字列(テキスト)を書換える

▼質問
HTML内の文字列(テキスト)を動的に書換えたいんだ。

何か良い方法はないか教えてくれ!

▼回答
あるよ!

P要素のタグで文字列を囲ってあげて

それに、id属性を付けてやって

次の様にアクセスすれば書き換わるよ。


<p id="id_test">テスト</p>

document.getElementById( 'id_test' ).innerHTML = "書き換わったかな?";


This page is powered by Blogger. Isn't yours?