1

パラメータを使用して関数を作成しましたが、機能しません。

これは私のコードです:

 function hideQuestion( _hideQuestion, _showQuestion){
   $('#_showQuestion').removeClass('hideOnInit');
   $('#_hideQuestion').addClass('hideOnInit');
   }

このような機能を使えば

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion(question1, question2);' data-role='button'></a>

...何も起こりません。

どうすれば修正できますか?

4

3 に答える 3

16

parameter関数変数を使用する必要があり、constant string代わりに使用しています。また、idsfromonclickを攪拌定数として渡します。

function hideQuestion( _hideQuestion, _showQuestion){
   $('#' + _showQuestion).removeClass('hideOnInit');
   $('#' + _hideQuestion).addClass('hideOnInit');
}

変化する

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion(question1, question2);' data-role='button'></a>

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion("question1", "question2");' data-role='button'></a>

javascriptでは、文字列は引用符で囲むsingleか、double引用符で囲むことができ、私たちが行ったように組み合わせることができますonclick

 onclick='hideQuestion("question1", "question2");' 
于 2013-01-03T07:50:41.847 に答える
0

関数とパラメータは問題ありませんが、関数でパラメータを使用していません...これを試してください。

function hideQuestion( _hideQuestion, _showQuestion){
   $('#'+_showQuestion).removeClass('hideOnInit');  //using the set variable here...
   $('#'+_hideQuestion).addClass('hideOnInit');

}

そしてあなたのhtml、あなたはパラメータを渡す必要があります..ここで私は文字列を送っています

<a id='_b_Startpage2' href=\"#Question_01_01\" onclick='hideQuestion("question1", "question2");' data-role='button'></a>  // sending thevariable to the functin as parameter
于 2013-01-03T07:53:01.237 に答える
0

Adilのソリューションは機能するはずです。"#_showQuestion"あなたの問題は、あなたのコードであなたが変数を探していて、"#_hideQuestion"あなたが宣言していないか、見つけることに興味がないということです

于 2013-01-03T07:53:54.977 に答える