【发布时间】:2012-09-06 01:12:38
【问题描述】:
虽然看起来很奇怪,但我的脚本的一部分看起来像这样...... 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>
在我的代码中间...
在除谷歌浏览器之外的所有浏览器中都能正常工作吗?为什么?
【问题讨论】:
-
控制台中是否有任何异常可以与我们分享?
-
你不能使用 require("jQuery/main_function.js");使用 include 而不是读取内容并在 php 加载之前回显它。
-
@JapanPro 为什么
include会比require更好? -
为什么你的 switch 语句中有那些花括号?
-
酷——至少你知道你的脚本被调用了!它可能与 Sheikh 发布的答案有关(关于 val())?
标签: php javascript jquery google-chrome