由于 javascript 获取 PHP 值,代码无法正常运行,我不知道如何比较它们

<div class="content">

            <h1>Üdvözöllek, <?php echo $nickname; ?>! </h2>

            <h4>Válasszon hetet: </h4>


            <select class="select-selected" id="1" name="het" onchange="checkclass()">

                <option disabled selected value>Hét</option>

                <option value="1"><?php echo $sd->format('m.d')," - ", $ed->format('m.d');?></option>

                <option value="2"><?php echo $sd2->format('m.d')," - ", $ed2->format('m.d');?></option>

                <option value="3"><?php echo $sd3->format('m.d')," - ", $ed3->format('m.d');?></option>

            </select>


        </div >

        <div>


            <a id="class">

                <select class="select-selected" id="2" onchange="checksubject()" name="osztaly">

                <option disabled selected value><?php echo $class; ?></option></select>

            </a>

            <a id="subject">

                <select class="select-selected" id="3" name="tantargy">

                <option disabled selected value><?php echo $subject; ?></option></select>

            </a>

            <a id="bontotte"></a>

            <a id="classtwo"></a>

        </div>


        <script>

因此,最后一个不会使其成为要填写的选择框,就像另一个名为“osztaly”的选择框一样。我认为 javascript 中的 IF 标记有问题,因为这些值无法比较:)


aluckdog
浏览 105回答 2
2回答

慕后森

由于狄更斯找到了使代码工作的正确方法,因此这里是正确输出的示例。本质上源有一些小错误,这里被消除了function checkclass() {&nbsp; &nbsp; &nbsp; &nbsp; var het = document.getElementById('1').value;&nbsp; &nbsp; &nbsp; &nbsp; if(1<=het){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var onosztaly =&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<select class="select-selected" id="2" onchange="checksubject()" name="osztaly">'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option disabled selected value>class</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class1">class1</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class2">class2</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class3">class3</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class4">class4</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class5">class5</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class6">class6</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="class7">class7</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</select>';&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById("class").innerHTML =(onosztaly);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; function checksubject() {&nbsp; &nbsp; &nbsp; &nbsp; var onsub = '<select class="select-selected" name="tantargy">'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option disabled selected value>subject</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="subject1">subject1</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="subject2">subject2</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="subject3">subject3</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<option value="subject4">subject4</option>'+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '</select>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.getElementById("subject").innerHTML =(onsub);&nbsp; &nbsp; &nbsp; &nbsp; }<div class="content">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1>Üdvözöllek, nickname! </h2>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h4>Válasszon hetet: </h4>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select class="select-selected" id="1" name="het" onchange="checkclass()">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option disabled selected value>Hét</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="1">date1</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="2">Date2</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option value="3">Date3</option>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </select>&nbsp; &nbsp; &nbsp; &nbsp; </div >&nbsp; &nbsp; &nbsp; &nbsp; <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a id="class">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select class="select-selected" id="2" onchange="checksubject()" name="osztaly">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option disabled selected value>Class</option></select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a id="subject">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <select class="select-selected" id="3" name="tantargy">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <option disabled selected value>Subject</option></select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a id="bontotte"></a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a id="classtwo"></a>&nbsp; &nbsp; &nbsp; &nbsp; </div>

德玛西亚99

您已通过 javascript 覆盖了自己的选择框更改此代码&nbsp;var&nbsp;onosztaly&nbsp;=&nbsp; &nbsp;&nbsp;&nbsp;'<select&nbsp;class="select-selected"&nbsp;name="osztaly">'+到&nbsp;var&nbsp;onosztaly&nbsp;=&nbsp; &nbsp;&nbsp;&nbsp;'<select&nbsp;class="select-selected"&nbsp;id="2"&nbsp;onchange="checksubject()"&nbsp;name="osztaly">'+它将起作用,意味着当日期更改时,选择框的 ID 和更改事件都会丢失坦白说你的设计不好,有有效的方法来添加选项和删除选项,innerHTML是非常旧的风格问题正文表明————javascript getting PHP values这种理解是错误的您的整个代码呈现为运行 HTML 并提供给浏览器,浏览器中不再有 PHP,只有您正在为下拉更改所做的浏览器编码所以当你认为实际上是从 PHP 读取值时,这是不正确的理解您仅在 javascript 中直接读取 HTML 组件值
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5