さて、私のタイトルがあまり有益ではないことはわかっています。説明させてください。
jQueryでやろうとしているページがあります。彼らのページ (古いページ) には、私の (新しい) ページに持ち込む選択ドロップダウン メニューがあります。彼らの select ドロップダウンは li 要素で ul を使用していますが、私のものは option 要素で select を使用しています。
ここに私が持っているものがあります:
var totalQuestions = jQuery('.rcbItem').length; //get the total elements in theirs
for ( x = 0; x < totalQuestions; x++) //for loop to create the dropdown on mine
{
var questionText = jQuery('.rcbItem:eq(' + x + ')').html();
jQuery('#selectQuestion').append(jQuery(document.createElement('option')).attr(
{
'value' : "Question" + x
}).html(questionText));
}
var strQuestion = jQuery('#ctl00_ContentPlaceHolder1_ddlQuestion_Input').val(); //gets the value currently in THEIR select field
var objQuestionNext = jQuery("#selectQuestion").find("option:contains('" + strQuestion + "')");
objQuestionNext.attr(
{
selected : 'true'
}); //finds the question in MY list that matches THEIR select field, and then selects that one
これは、ドロップダウン リストから質問を選択するたびに実行されるコードです。
jQuery('#selectQuestion').change(function()
{
strQuestion = jQuery('#selectQuestion :selected').val(); //get the value of "option", which is Question + x
strAnswer = jQuery('#txtQuestionAnswer').val();
intQuestionNumber = strQuestion.substr(8, 2).trim(); //gets the number (so Question + x becomes x)
jQuery('#ctl00_ContentPlaceHolder1_ddlQuestion_Arrow')[0].click(); //I click THEIR dropdown menu
jQuery('.rcbItem:eq(' + (intQuestionNumber-1) + ')').click(); //Select THEIR li element that matches MINE)
jQuery('#ctl00_ContentPlaceHolder1_ctbAnswer').val(strAnswer);
});
これは 90% の確率で機能します。
ただし、リストの最後のオプションを選択すると、次のようになります。それは問題ありませんが、リストから別の質問を選択すると、必要な質問のすぐ上の質問が選択され始め、ページを完全にリロードするまでそれを続けます。これは、ドロップダウンの最後の要素を選択した場合にのみ発生します。
私はこれについて頭を悩ませてきましたが、答えは見つかりませんでした。誰でも洞察を提供できますか?ありがとう。
編集:私はついに問題を見つけました。彼らのコードでは、クリックが発生したときに、li 要素のすべてが持っていた .rcbItem クラスが .rcbHover クラスによって上書きされていました。それを修正するために、基本的に .rcbItem をに変更しましたがjQuery('.rcbList li')....
、今では完全に機能します。
助けてくれてありがとう。