0

with属性<img>を使用して関数からタグを削除しようとしていますが、機能しません。以下に、私が行っていることの簡単なコードを示します。id.remove()

<script>
function verify(img)
{
   if(/*somecondition*/)
   removetag_setother();
   else
   //do something
}
function removetag_setother()
{
   $("#1").remove();
   text="<p>hello</p>";
   $("body").append(text);
}
</script>
<body>
<img id="1" onclick="verify(this)" src="image1.png">
</body>

コンソールのログを確認すると、次のメッセージが表示されました: ReferenceError: $ is not defined

4

1 に答える 1

0

問題は空のifandelseステートメントです。句を置き換えif(/*somecondition*/)if(true)コメントアウトします。else

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
function verify(img)
{
   if(true)
       removetag_setother();
   //else
       //do something
}
function removetag_setother()
{
   $("#1").remove();
   text="<p>hello</p>";
   $("body").append(text);
}
</script>
<body>

于 2013-03-25T20:42:55.110 に答える