以下のコードを使用してオブジェクト リテラルを作成しました。すべて正常に動作します。
ただし、オブジェクト コンストラクターと対応するオブジェクトを作成してオブジェクト リテラルを書き換えようとしてから、「ドット構文」を使用してメソッドを実行すると、何も起こりません。何が間違っているのかわかりません。以下の例では、JQuery を使用しています。
ありがとうございました。
オブジェクトリテラル (作業中)
<!DOCTYPE=HTML>
<meta chartset="UTF-8">
<title> whatever </title>
<script type="text/javascript"> </script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" charset="utf-8"></script>
<div id="theDiv"></div>
<style>
#theDiv{
position:absolute;
width:200px;
height:200px;
background:#f00;
}
</style>
<script>
$(document).ready(function(){
var myObj = {};
myObj.doThing = function () {
$("#theDiv").toggle(3000);
};
myObj.doThing();
});
</script>
オブジェクトを持つコンストラクター (非稼働)
<!DOCTYPE=HTML>
<meta chartset="UTF-8">
<title> whatever </title>
<script type="text/javascript"> </script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" charset="utf-8"></script>
<div id="theDiv"></div>
<style>
#theDiv{
position:absolute;
width:200px;
height:200px;
background:#f00;
}
</style>
<script>
$(document).ready(function(){
function ConstructorExample (){
this.move = function () {
$("#theDiv".toggle(3000);
};
};
var objExample = new ConstructorExample();
objExample.move();
});
</script>