[英]jQuery script not working in google chrome
As odd as it may seem I have a part of my script that looks like this... php is controlling access to my jQuery function; 奇怪的是,我的脚本的一部分看起来像这样……php正在控制对jQuery函数的访问; please excuse the fact that there maybe some redundant code here, but allow me to explain the main issue here.
请原谅这里可能有一些多余的代码,但是请允许我在这里解释主要问题。
Here is a code excerpt of php: 这是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>';
}
As you can see in the php code, if the user is active, as determined from a database call, it will require main_function.js in the html, thus dropping this: 如您在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>
in the middle of my code... 在我的代码中间...
Works fine in all browsers except google chrome? 在所有浏览器(谷歌浏览器除外)上都能正常工作吗? Why?
为什么?
You are swirching option's value like 您正在旋转选项的值,例如
switch($('#'+elementId).val())
but in your element (option) I didn't see any value
assigned (from the comment you provided) 但在您的元素(选项)中,我没有看到分配的任何
value
(根据您提供的注释)
<option id="video0" onclick="option_click(this.id)">Video</option>
Update: 更新:
Your approach (not working in Chrome) 您的方法(不适用于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>
Proper way (Working in all browsers) 正确的方式(在所有浏览器中均可使用)
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.