jQuery脚本无法在谷歌浏览器中运行

时间:2012-09-06 01:12:39

标签: php javascript jquery google-chrome

看起来很奇怪,我的脚本看起来像这样...... php正在控制对jQuery函数的访问;请原谅这里可能有一些冗余代码,但请允许我在这里解释一下主要问题。

以下是php的代码摘录:

<?php
        if($user_info['ACTIVE'] == 'Y')
            {
                require("jQuery/main_function.js");
                require("edit_profile.php");
            }elseif(!isset($_GET['resend']))
            {
                echo '<div id="profile_info"><p>In order to modify or setup your seller profile your account must be activated.<br />
                Check your email; if you did not receive an email, <a href="profile.php?resend">Click here</a> to have another one dispatched.</p>';
                echo '<p>You can however complete your contact information <a href="user_contact.php">here</a>';
            }

正如您在php代码中看到的那样,如果用户处于活动状态(根据数据库调用确定),则需要在html中使用main_function.js,从而删除此内容:

<script type="text/javascript">
function option_click(elementId)
    {
        $(document).ready(function(){
            alert('testing1');
            var defaultString = "Upload";
            var elementNum = elementId.substr(elementId.length-1, 1);
            switch($('#'+elementId).val())
            {
                case 'Video':
                {
                    alert('testing in chrome');
                    $('.set_time'+elementNum).prop('type', 'hidden');
                    $('.product_upload'+elementNum).prop('type', 'file');
                    $('.content_upload'+elementNum).html(defaultString + ' a ' + 'video file:');
                    break;  
                }
                case 'Time':
                {
                    $('.content_upload'+elementNum).html('How much time?');
                    $('.product_upload'+elementNum).prop('type', 'hidden');
                    $('.set_time'+elementNum).prop('type', 'text');
                    break;
                }
                case 'Music/Audio':
                {
                    $('.set_time'+elementNum).prop('type', 'hidden');
                    $('.product_upload'+elementNum).prop('type', 'file');
                    $('.content_upload'+elementNum).html(defaultString + ' a ' + 'music file');
                    break;
                }
                case 'Ebook':
                {
                    $('.set_time'+elementNum).prop('type', 'hidden');
                    $('.product_upload'+elementNum).prop('type', 'file');
                    $('.content_upload'+elementNum).html(defaultString + ' an ' + 'ebook file');
                    break;  
                }
                case 'Tutorial/Docs':
                {
                    $('.set_time'+elementNum).prop('type', 'hidden');
                    $('.product_upload'+elementNum).prop('type', 'file');
                    $('.content_upload'+elementNum).html(defaultString + ' a ' + 'tutorial file');  
                    break;
                }
            }
        });
    }
</script>

在我的代码中间......

除谷歌浏览器外,所有浏览器都能正常使用?为什么呢?

1 个答案:

答案 0 :(得分:0)

您正在调整选项的值,如

switch($('#'+elementId).val())

但在您的元素(选项)中,我没有看到任何value已分配(来自您提供的评论)

<option id="video0" onclick="option_click(this.id)">Video</option>

<强>更新

您的方法(不在Chrome中运行)

<select>
   <optgroup label="Swedish Cars">
       <option id="volvo" onclick="option_click(this.id)">Volvo</option>
       <option id="saab" onclick="option_click(this.id)">Saab</option>
   </optgroup>

DEMO

正确的方法(在所有浏览器中工作)

<select onchange="option_click(this.value)">
    <optgroup label="Swedish Cars">
        <option value="volvo" id="volvo">Volvo</option>
        <option value="saab" id="saab">Saab</option>
    </optgroup>
</select>

DEMO

An example with switch statement here