Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重新影响div会让jquery表现得很怪异_Php_Javascript_Jquery_Html - Fatal编程技术网

Php 重新影响div会让jquery表现得很怪异

Php 重新影响div会让jquery表现得很怪异,php,javascript,jquery,html,Php,Javascript,Jquery,Html,当我用javascript编写代码时,我意识到了一些奇怪的事情,尤其是使用一些jquery函数 这是我的密码 <?php // Encoded in UTF-8 if(isset($_SESSION['username'])) { ?> <script type="text/javascript"> function showEvent(nid) { $j=jQuery.noConflict(); $j.g

当我用javascript编写代码时,我意识到了一些奇怪的事情,尤其是使用一些jquery函数

这是我的密码

<?php // Encoded in UTF-8
    if(isset($_SESSION['username']))
    {
?>

<script type="text/javascript">
    function showEvent(nid)
    {
        $j=jQuery.noConflict();
        $j.get("getGestionEvent.php?type=show&nid="+nid, function(data){
            document.getElementById("eventdiv").innerHTML = data;
        });
    }
</script>

<h2> Event </h2>
<fieldset>
<legend> Add </legend>
<div style="margin-top:10px;">
    <label for="date"> Date : </label>
    <span style="margin-left:20px;">
        <button id="ButtonCreationDemoButton">
            <img src="img/calendar.png" alt="[calendar icon]"/>
        </button>
    </span>
</div>
<form name="events" action="index.php?p=event" method="post">
<div style="margin-top:5px;">
    <span style="margin-left:-1px;">
        <input type="text" name="ButtonCreationDemoInput" id="ButtonCreationDemoInput"/>
    </span>
</div>
<div style="margin-top:10px;">
    <label for="date"> Description : </label>
</div>
<div style="margin-top:5px;">
    <span style="margin-left:-1px;">
        <input type="text" name="desc" id="desc" maxlength="100">
    </span>
</div>
<div style="margin-top:5px;">
    <input type="submit" value="Ajouter">
<div>
</fieldset>
</form>
<div id="eventdiv"></div>
<script type="text/javascript">
    // If I don't call the function, the other script doesn't make an error
    showEvent(0);
</script>

<script>
    $('#ButtonCreationDemoButton').click(
      function(e) {
        $('#ButtonCreationDemoInput').AnyTime_noPicker().AnyTime_picker().focus();
        e.preventDefault();
      } );
</script>
<?php
    }
    else
    {
        echo '<p style="color:red"> You cannot see this page. </p>';
    }
?>

函数showEvent(nid)
{
$j=jQuery.noConflict();
$j.get(“getGestionEvent.php?type=show&nid=“+nid,函数(数据){
document.getElementById(“eventdiv”).innerHTML=数据;
});
}
事件
添加
日期:
说明:
//如果我不调用该函数,则另一个脚本不会出错
showEvent(0);
$(“#按钮创建演示按钮”)。单击(
职能(e){
$(“#按钮创建DemoInput”).AnyTime_noPicker().AnyTime_picker().focus();
e、 预防默认值();
} );
这是一个带有2个文本框的简单表单,但我有一个带有日历图像的按钮,可以使日历显示在文本框的顶部按钮CreationDemoInput,使用户可以轻松选择日期。如果删除调用函数showEvent()的行,则日历显示不会出现问题。但是如果我让该函数在那里运行,我会得到错误并且看不到日历:

未捕获的TypeError:对象[object DOMWindow]的属性“$”不是函数

它指向以下行:$(“#ButtonCreationDemoButton”)。单击(

顺便说一下,showEvent只为名为eventdiv的div提供一个数据库中的数据表

这不是我第一次看到这样的问题。只有当我重新影响div的内容时才会发生这种情况


有人能帮我一下吗?

$是jQuery对象的标准变量别名。但是您正在使用。这将删除
$
别名。相反,您必须使用
jQuery
,即
jQuery(“#按钮创建DemoButton”)

基本上,
showEvent()
被调用,删除
$
别名,然后您尝试在下面的
脚本
标记中使用它


但是,在您的代码中,您不只是调用
jQuery.noConflict()
,而是将其分配给变量
$j
。这允许您使用
$j
作为jQuery别名,即
$j('ButtonCreation…')

,非常感谢!!现在我理解了错误,并且工作正常:D