Селектор идентификатора jQuery не работает для IE7 (.show () /. hide ()) - PullRequest
1 голос
/ 20 мая 2011

При загрузке jQuery я пытаюсь скрыть / показать некоторые div в зависимости от условия. Все работает вне IE7. Я сломал его и обнаружил, что следующий селектор класса будет работать :

$('.medication_div').hide();

Но селектор идентификаторов, который мне нужен, не работает (Примечание: я пробовал хард-кодовые значения, которые тоже не работали.

//Get the name of the medication selected
var medication_selected = $("ul#medication_classes li:last-child p").text();
//Show the div associated with the selected medication card
$("#"+medication_selected).show();

Вот HTML-код, сгенерированный после запуска:

<ul id="medication_classes">
            <li>
                <p>Celexa</p>
                <input id="Meds_0" name="Meds[0]" type="hidden" value="Celexa" />
            </li>

            <li>
                <p>Lisinopril</p>
                <input id="Meds_1" name="Meds[1]" type="hidden" value="Lisinopril" />
            </li>
        </ul>
        <div id="results_detail" class="grid_12 alpha">
            <ul>
                <li>

                    <div class="medication_div" id="Celexa">
                        <p id="class_trigger">Protocol Set Triggering: General<input id="Celexa_ProtocolSetID" name="Celexa[ProtocolSetID]" type="hidden" value="1" /></p><br>
                        <p class="left_input">Does the patient still have active refills for Celexa?</p> 
                        <div class="right_input">No:<input id="Celexa_ActiveRefills_No" name="Celexa[ActiveRefills]" type="radio" value="No" />  Yes:<input id="Celexa_ActiveRefills_Yes" name="Celexa[ActiveRefills]" type="radio" value="Yes" /></div><br/>
                        <div class="clear"></div>
                        <div id="Celexa_notActive">
                            <p>Approve the Celexa refill as indicated in the patient record.</p>

                        </div>


                        <div id="Celexa_active">
                        <p class="left_input" id="dose_change">When was the dosage for this medication last changed?</p> <div class="right_input"><input class="date" id="Celexa_MedicationChangeDate" name="Celexa[MedicationChangeDate]" type="text" /></div><br/>
                        <div class="clear"></div>


                        <div class="table_header med_info">
                            <h5>Fill in the following as much possible in order to find the most relevant protocol.</h5>
                        </div>

                        <table width="846">
                            <tr id="labels">
                                <th width="33%">Name</th>
                                <th width="33%">Value</th>
                                <th width="33%">Result Date</th>
                            </tr>   
                            <tr>
                                <td width="33%">Medication Start<input id="Celexa_TestResult_0_Name" name="Celexa[TestResult][0][Name]" type="hidden" value="Medication Start" />

                                </td>
                                <td width="33%">
                                    <p>N/A</p>
                                </td>
                                <td width="33%">
                                    <input class="date" id="Celexa_TestResult_0_Date" name="Celexa[TestResult][0][Date]" type="text" />
                                </td>
                            </tr>

                        </table>

                        <label>Note to physician about refill request:</label><textarea class="md_note" id="Celexa_Note" name="Celexa[Note]"></textarea>
                    </div>
                    </div>
                </li>
                <li>
                    <div class="medication_div" id="Lisinopril">
                        <p id="class_trigger">Protocol Set Triggering: Hypertension Medications<input id="Lisinopril_ProtocolSetID" name="Lisinopril[ProtocolSetID]" type="hidden" value="4" /></p><br>

                        <p class="left_input">Does the patient still have active refills for Lisinopril?</p> 
                        <div class="right_input">No:<input id="Lisinopril_ActiveRefills_No" name="Lisinopril[ActiveRefills]" type="radio" value="No" />  Yes:<input id="Lisinopril_ActiveRefills_Yes" name="Lisinopril[ActiveRefills]" type="radio" value="Yes" /></div><br/>
                        <div class="clear"></div>
                        <div id="Lisinopril_notActive">
                            <p>Approve the Lisinopril refill as indicated in the patient record.</p>
                        </div>


                        <div id="Lisinopril_active">

                        <p class="left_input" id="dose_change">When was the dosage for this medication last changed?</p> <div class="right_input"><input class="date" id="Lisinopril_MedicationChangeDate" name="Lisinopril[MedicationChangeDate]" type="text" /></div><br/>
                        <div class="clear"></div>


                        <div class="table_header med_info">
                            <h5>Fill in the following as much possible in order to find the most relevant protocol.</h5>
                        </div>
                        <table width="846">
                            <tr id="labels">

                                <th width="33%">Name</th>
                                <th width="33%">Value</th>
                                <th width="33%">Result Date</th>
                            </tr>   
                            <tr>
                                <td width="33%">Medication Start<input id="Lisinopril_TestResult_0_Name" name="Lisinopril[TestResult][0][Name]" type="hidden" value="Medication Start" />
                                </td>

                                <td width="33%">
                                    <p>N/A</p>
                                </td>
                                <td width="33%">
                                    <input class="date" id="Lisinopril_TestResult_0_Date" name="Lisinopril[TestResult][0][Date]" type="text" />
                                </td>
                            </tr>
                            <tr>

                                <td width="33%">Creatinine<input id="Lisinopril_TestResult_1_Name" name="Lisinopril[TestResult][1][Name]" type="hidden" value="Creatinine" />
                                </td>
                                <td width="33%">
                                    <input id="Lisinopril_TestResult_1_Value" name="Lisinopril[TestResult][1][Value]" type="text" />
                                </td>
                                <td width="33%">
                                    <input class="date" id="Lisinopril_TestResult_1_Date" name="Lisinopril[TestResult][1][Date]" type="text" />
                                </td>

                            </tr>
                        </table>

                        <label>Note to physician about refill request:</label><textarea class="md_note" id="Lisinopril_Note" name="Lisinopril[Note]"></textarea>
                    </div>
                    </div>
                </li>
            </ul>
        </div>

При жестком кодировании для приведенного выше примера, я жестко запрограммировал безрезультатно:

$("#Celexa").show();

Есть идеи?

Ответы [ 2 ]

1 голос
/ 20 мая 2011

Оказывается, код Rails генерировал дополнительный символ, который интерпретировался только в IE7.На данный момент я до сих пор не уверен, что это за символ (возможно, не в кодировке Юникод), но я исправил проблему с помощью селектора подстановочных знаков jQuery:

$("div[id^="+medication_selected+"]").show();
0 голосов
/ 20 мая 2011

отлично работал на моем ie7.Проверьте ваш CSS / стиль в Firefox.

Кстати - попробуйте использовать JSON, шаблоны и данные JQuery для лучших результатов.например:

HTML:

<p>select one:</p>
<ul id="medication_classes">
</ul>
 <div id="medication_detail">
<p>Protocol Set Triggering: <span class="data-protocol">General</span></p>
<p>Does the patient still have active refills for <span class="data-name">Celexa</span>?</p> 
<p>No:<input type="radio" value="No" />  Yes:<input type="radio" value="Yes" /></p>
<p>Approve the <span class="data-name">Celexa</span> refill as indicated in the patient record.</p>
<p>When was the dosage for this medication last changed?</p> 
<p><input class="date" /></p>
<p>Fill in the following as much possible in order to find the most relevant protocol.</p>

JS:

$(function () {
        var medications = [
            { name: 'Celexa', protocol: 'General' },
            { name: 'Lisinopril ', protocol: 'Hypertension Medications' }
        ];


        for (var medicationID in medications) {
            var medication = medications[medicationID];

            $('<li>')
                .data('medicineData', medication)
                .text(medication.name)
                .appendTo('#medication_classes')
                .click(function () {
                    var medicineData = $(this).data('medicineData');
                    $('.data-name').text(medicineData.name);
                    $('.data-protocol').text(medicineData.protocol);
                });
        }

    });

может использовать pure - хороший движок шаблонов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...