プロが教えるわが家の防犯対策術!

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
<script src="components/loader.js"></script>
<script src="lib/onsenui/js/onsenui.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></s …

<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="lib/onsenui/css/onsenui.css">
<link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css">
<link rel="stylesheet" href="css/style.css">

<script>
var count = 0;

function increment() {
count++;
update();

}

function update() {
var str = ('0' + count).substr(-2);
$('img.counter-digit').each(function(i,e){ if (i<str.length) e.src = "img/noo_@.png".replace(/@/, str.charAt(i)) });

}



$(function() {
$('.count-button').on("touchend", increment);
update();
})

$(function() {
$('.count-button').on('.count-button','click',function(){
$(this).remove();
$('#sortable').append($(this).clone().addClass("ui-sortable-handle"));
});
});
function openYahoo(){
$(this).remove();
$('#unList').append($(this).clone().removeClass("ui-sortable-handle"))
}

setTimeout("openYahoo()", 3000);



</script>


以上のプログラムでcount-buttonを一度クリックするとopenYahooの実行によりボタンが消えるというプログラムを作成していたのですが、「uncaught TypeError:Cannot read property 'ownerDocument' of undefine」というエラーがあり、カウントはできるのですがボタンが消えてくれません

初歩的なことかもしれませんが助けてください。

A 回答 (2件)

こんにちは



ざっと眺めただけで、確認はしていませんが・・・

>count-buttonを一度クリックするとopenYahooの実行により~
count-buttonのクリックでは、openYahoo()は実行されるようになっていないと思いますけれど??

関数openYahooが実行されるのは、最後の1行の
 setTimeout("openYahoo()", 3000);
を処理しようとする時だけではないでしょうか?
しかもthisが定まっていないので、関数の中で$(this)として引用されているthisは一体何になっているのでしょうか?
(グローバルオブジェクトかな?)

想像するところ、そこでエラーになっているのではないでしょうか?
(実際のエラー発生個所は、jQuery内の解釈構文中かも知れませんが・・・)
    • good
    • 0
この回答へのお礼

ボタンを押してカウントした後に
openYahooが起動できるようにしたらいいんですかね?

私が修正しても思うように動いてくれないので
よかったらサンプルコードを記載していただけませんか?
お忙しいとは思いますが、お願いします

お礼日時:2018/02/05 15:56

スタイルシートがやたら拡張されていてなんだかわかりません



HTMLとそれに対してどういうトリガーでどうしたいのか明示されたほうがよいでしょう
    • good
    • 1
この回答へのお礼

<body id="mainn">

<div class="page1_background">
<form name="zbotoon"method="post" action="zukann.html">
<button type="image" id="bottonz"><img src="img/zbotton.png"style="width:180px;height:120px"></button>
</form>
</div>
<button class="count-button"><img src="img/megane.png" width="100"height="50"style="position: relative;
top: 60px;right:50px;"></button>
<button class="count-button"><img src="img/megane.png" width="100"height="50"style="position: relative;
top: 100px;left:50px;"></button>

<div class="counter">
<img src="img/no_00.png" height="100"width="80" class="counter-digit" style="position: relative;
top: -200px;right:100px;">
<img src="img/no_00.png" height="100"width="80" class="counter-digit" style="position: relative;
top: -200px;right:155px;">
</div>




</body>
</html>

HTMLはこちらです。

お礼日時:2018/02/05 14:38

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!