如何将NoConflict与jquery一起用于本地和外部库?

时间:2016-08-02 14:31:00

标签: javascript php jquery

好吧,伙计们,我有两个功能完美无缺地工作,但不会一起工作,我用Google搜索并发现我可以使用JQuery.NoConflict()函数来避免冲突(显而易见)但我不能管理它工作。

以下是代码:

<script type="text/javascript" src="//code.jquery.com/jquery-3.1.0.js"></script>
<script type='text/javascript'>
    window.onload=function(){
    $("div").on('click', function() {
        var classe = $(this).attr("class");
      $("#"+classe).show();
      for(var i=0; i<10; ++i){
        if(i!=classe){
            $("#"+i).hide();
        }
      }
    });
    }

<script type="text/javascript" src="autocompletar/lib/jquery.js"></script>
<script type='text/javascript' src='autocompletar/jquery.autocomplete.js'></script>
<script type="text/javascript">
$().ready(function() {

    $("#outdsconc").autocomplete("autocompletar/DescConc.php", {
    width: 400,
    max: 100,
    scroll: true,
    scrollHeight: 300,
    matchContains: true,
    selectFirst: false
});
$("#outcdconc").autocomplete("autocompletar/CodConc.php", {
    width: 500,
    max: 100,
    scroll: true,
    scrollHeight: 300,
    matchContains: true,
    selectFirst: false
});

$("#outcdconc").result(function(event, data, formatted) {
    if (data) 
        document.getElementById('outdsconc').value = data[1];
});
$("#outdsconc").result(function(event, data, formatted) {
    if (data)
        document.getElementById('outcdconc').value = data[1];
});

});
</script>

CodConc.php:

$q = $_GET['q'];
$query_pro = "SELECT CD_AMOSTRACONCORRENTE, DS_AMOSTRACONCORRENTE FROM SPM_AMOSTRACONCORRENTE WHERE CD_AMOSTRACONCORRENTE LIKE '%" . strtoupper($q) . "%' ";
$pro = mssql_query(strtoupper($query_pro)) or die('Erro na query...');

while ($row_pro = mssql_fetch_array($pro)) {
    $items[] = $row_pro["DS_AMOSTRACONCORRENTE"] ."|". $row_pro["CD_AMOSTRACONCORRENTE"];
} 

if (count($items)>0) {
    foreach ($items as $key=>$value) {
        $value = explode("|",$value);
        echo trim($value[1]) . "|" . trim($value[0]) . "\n";

        }
}

DescConc.php:

$q = $_GET['q'];
$query_pro = "SELECT CD_AMOSTRACONCORRENTE, DS_AMOSTRACONCORRENTE FROM SPM_AMOSTRACONCORRENTE WHERE DS_AMOSTRACONCORRENTE LIKE '%" . strtoupper($q) . "%' ";
$pro = mssql_query($query_pro) or die('Erro na query');

while ($row_pro = mssql_fetch_array($pro)) {
    $items[] = $row_pro["CD_AMOSTRACONCORRENTE"] ."|". $row_pro["DS_AMOSTRACONCORRENTE"];
} 

foreach ($items as $key=>$value) {
    $value = explode("|",$value);
    echo trim($value[1]) . "|" . trim($value[0]) . "\n";
}

和html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Administração de Usu&aacute;rios</title>

<style type="text/css">
        .invisivel{
            display:none;
        }
        #titulo{
            border:1px solid #FC0;
            background-color:#FFF6BF;
            width:600px;
            height:20px;
            padding:5px;
            text-align:center;
            margin:0 auto;
            font-size:15px
            }
</style>
<-- scripts here -->
</head>
<body>
<table>
    <tr>
    <td>
        <div id="titulo">Provas de Desenvolvimento</div>
    </td>
    </tr>
    <tr>
        <td>
        <table>
                <tr>
                    <td width="75px" align="right">Pesquisa:</td>
                    <td height="15px"><input name="outcdpesquisa" size="8" value="<?php echo $row_pesq['CD_PESQUISA'];?>"/></td>
                    <td><input name="outdspesquisa" size="45" value="<?php echo $row_pesq['DS_PESQUISA'];?>"/></td><td></td></td>
                </tr>
        </table>
        </td>
    </tr>
    <tr>
        <td>
        <table>
            <tr>
                <td width="75px" align="right">Concorrente:</td>
                <td height="15px">
                <input name="outcdconc" type="text" id="outcdconc" value="<?php echo $_POST['outcdconc']; ?>" size="8"/></td>
                <td>
                <input name="outdsconc" type="text" id="outdsconc" value="<?php echo $_POST['outdsconc']; ?>" size="45"/></td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
        <td>
        <table>
            <tr>
                <td width="75px" align="right">Produto:</td>
                <td height="15px"><input name="outproduto" size="62"/></td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
    <td id="esquerda">
        <div id="aba" class="1">Escolher Provas</div>
    </td>
    </tr>
    <tr>
    <td id="esquerda">
        <table class="invisivel" id="1">
        <form name="escolherprovas">
            <tr>
                <td>
                <table>
                    <tr>
                        <td width="75px" align="right">Usu&aacute;rio:&nbsp;</td>
                        <td height="15px"><input name="epcdusu" size="8"/></td>
                        <td><input name="epdescusu" size="45"/></td><td></td></td>
                    </tr>
                </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="75px" align="right">Unidade:</td>
                        <td><select name="epunid">
                              <option value="gr">gr</option>
                              <option value="kg">Kg</option>
                              <option value="ml">ml</option>
                              <option value="li">li</option>
                            </select></td>
                        <td >Lote da Prova:</td>
                        <td><input name="eploteprova" size="15"/></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="75px" align="right">Objetivo:</td>
                        <td><input name="epobjetivo" type="text" size="63" /></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="75px" align="right">Quantidade de<br />Saida Desejada:</td>
                        <td><input name="epqtd" size="5" /></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="75px" align="right">Data:</td>
                        <td><input name="epdata" type="date" value="<?php echo date('Y-m-d');?>" /></td>
                    </tr>
                    </table>
                </td>
            </tr>
        </form>
        </table>
    </td>
    </tr>

    <tr>
    <td>
        <div id="aba" class="2">Processo de Fabrica&ccedil;&atilde;o</div>
    </td>
    </tr>
    <tr>
    <td>
        <table class="invisivel" id="2">
            <form name="processodefabricacao">
                <tr>
                    <td>
                        <textarea name="pfdesc" rows="8" cols="70"></textarea>
                    </td>
                </tr>
            </form>
        </table>
    </td>
    </tr>

    <tr>
    <td>
        <div id="aba" class="3">Formula&ccedil;&atilde;o</div>
    </td>
    </tr>
    <tr>
    <td>
        <table class="invisivel" id="3">
            <form name="formulacao">
            <tr>
                <td>
                <table>
                    <tr>
                        <td width="25%" style="text-align:right;">Mat&eacute;ria Prima:</td>
                        <td height="15px"><input name="focdmatpri" size="8"/></td>
                        <td><input name="fodescmatpri"size="45"/></td><td></td>
                    </tr>
                </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td>Quantidade:</td>
                        <td><input name="foqtd" size="5" /></td>
                        <td>&nbsp;Lote:</td>
                        <td><input name="folote" size="8" /></td>
                        <td>&nbsp;Fornecedor:</td>
                        <td><input name="fofornec" size="16" /></td>
                        <td>&nbsp;Custo Unit.:</td>
                        <td><input name="focusto" size="5" /></td>
                    </tr>
                    </table>
                </td>
            </tr>

        </form>
        </table>
    </td>
    </tr>

    <tr>
    <td>
        <div id="aba" class="4">An&aacute;lises</div>
    </td>
    </tr>
    <tr>
    <td>
        <table class="invisivel" id="4">
            <form name="analises">
            <tr>
                <td>
                <table>
                    <tr>
                        <td width="25%" style="text-align:right;">An&aacute;lise:</td>
                        <td height="15px"><input name="ancdan" size="8"/></td>
                        <td><input name="andescan" size="46"/></td><td></td></td>
                    </tr>
                </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td>MAC:</td>
                        <td><input name="anmac" size="5" /></td>
                        <td>&nbsp;Unidade:</td>
                        <td><select name="anunid">
                              <option value="gr">gr</option>
                              <option value="kg">Kg</option>
                              <option value="ml">ml</option>
                              <option value="li">li</option>
                            </select></td>
                        <td>&nbsp;Detalhe:</td>
                        <td><input name="andetalhe" size="34" /></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td>Res. Conc.:</td>
                        <td><input name="anresconc" type="text" size="60" /></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td>Resultado:</td>
                        <td><input name="anres" type="text" size="15" /></td>
                        <td><button value="">Adicionar</button></td>
                    </tr>
                    </table>
                </td>
            </tr>

        </form>
        </table>
    </td>
    </tr>

    <tr>
    <td>
        <div id="aba" class="5">An&aacute;lises Especifica&ccedil;&atilde;o</div>
    </td>
    </tr>
    <tr>
    <td>
        <table class="invisivel" id="5" >
            <form name="analisesespecificacao">
            <tr>
                <td>
                <table>
                    <tr>
                        <td width="50px" align="right">An&aacute;lise:</td>
                        <td height="15px"><input name="aecdan" size="8"/></td>
                        <td><input name="aedescan" size="46"/></td><td></td></td>
                    </tr>
                </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="50px" align="right">N&ordm; Ensaio:</td>
                        <td><input name="aeensaio" size="5" /></td>
                        <td>&nbsp;UN:</td>
                        <td><select name="aeunid">
                              <option value="gr">gr</option>
                              <option value="kg">Kg</option>
                              <option value="ml">ml</option>
                              <option value="li">li</option>
                            </select></td>
                        <td>&nbsp;Detalhe:</td>
                        <td><input name="aedetalhe" size="34" /></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="50px" align="right">Status:</td>
                        <td><select name="aestatus">
                              <option value="1">1</option>
                              <option value="2">2</option>
                            </select></td>
                    </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td>
                    <table>
                    <tr>
                        <td width="50px" align="right">Especifica&ccedil;&atilde;o:</td>
                        <td><input name="aeespec" type="text" size="20" /></td>
                    </tr>
                    </table>
                </td>
            </tr>

        </form>
        </table>
    </td>
    </tr>

    <tr>
    <td>
        <div id="aba" class="6">Coment&aacute;rio</div>
    </td>
    </tr>
    <tr>
    <td>
        <table class="invisivel" id="6">
            <form name="comentario">
                <tr>
                    <td>
                        <textarea name="cocomentario" rows="8" cols="70"></textarea>
                    </td>
                </tr>
            </form>
        </table>
    </td>
    </tr>


</table>
        </body></html>

如果有人知道通过输入ID自动填写说明的简单方法,那就太棒了。

0 个答案:

没有答案