jQuery ID选择器不适用于IE7(.show()/。hide())

时间:2011-05-20 03:39:58

标签: jquery html css internet-explorer

在jQuery加载我试图隐藏/显示某些div取决于条件。一切都在IE7之外。我已将其分解,并且我发现以下类选择器工作:

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

但是,我需要的ID选择器没有(注意:我尝试了对代码值进行处理,这些代码值也没有用。

//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 个答案:

答案 0 :(得分:1)

原来Rails代码生成了一个额外的字符,只能在IE7中解释。到目前为止,我仍然不确定该字符是什么(可能是非unicode),但我通过使用jQuery通配符选择器修复了问题:

$("div[id^="+medication_selected+"]").show();

答案 1 :(得分:0)

在我的ie7上运作良好。 在firefox中检查你的css / style。

btw - 尝试使用json,templates和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);
                });
        }

    });

也许使用纯净 - 这是一个很好的模板引擎。