jQuery脚本在googlechrome中不起作用


jQuery script not working in 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>

在我的代码中间。。。

适用于除谷歌chrome之外的所有浏览器?为什么?

您正在像一样交换选项的值

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>

演示

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

<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>

演示

这里有一个带有switch语句的示例。