亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 PHP MySQL 中顯示選定的選項

在 PHP MySQL 中顯示選定的選項

PHP
狐的傳說 2023-05-12 15:27:32
我想顯示選擇的程序選項(selectedprg)并執行程序的COUNT(selectedcount)但目前點擊按鈕后沒有數據顯示。請協助解決這個問題。感謝您的時間。下拉選擇<select id="prg" name="prg"  class="demoInputBox" style="padding: 3px; width: 350px;">    <option value="">Select Programme</option>        <?php        //"SELECT * FROM marketing_data WHERE intake_year = '" . $_GET['intake_year'] . "'";        $sql = "SELECT DISTINCT student_prg FROM marketing_data";        $do = mysqli_query($conn, $sql);                          while($row = mysqli_fetch_array($do)){                              echo '<option value="'.$row['student_matric'].'" data-count="'.$row['count'].'">'.$row['student_prg'].'</option>';                          }                      ?>    </select>點擊按鈕后顯示數據<button onclick="myFunction()">Click me</button><p id="demo"></p><script>function myFunction() {  document.getElementById("demo").innerHTML = "The next intake for " +selectedprg + " will have " +selectedcount+ " students";}</script>Javascript<script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script type="text/javascript">$(document).ready(function(){$("#prg").change(function(){ var selectedprg = $('#prg option:selected').text(); var selectedcount = $('#prg option:selected').data('count');</script>截屏
查看完整描述

1 回答

?
慕雪6442864

TA貢獻1812條經驗 獲得超5個贊

一些注意事項:

  • selectedprg并且selectedcount不是全局可用的,你不能在你的函數中訪問它們。將它們移動/聲明在外面。

  • 你的$(document).ready(function(){$("#prg").change( function(){缺少他們的結束})部分。

使用瀏覽器的 DevTools 控制臺檢查錯誤。

嘗試這個:

<button onclick="myFunction()">Click me</button>


<p id="demo"></p>


<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>

<script type="text/javascript">

  var selectedprg = '';

  var selectedcount = 0;


  function myFunction() {

    document.getElementById("demo").innerHTML = "The next intake for " +selectedprg + " will have " +selectedcount+ " students";

  }


  $(document).ready(function(){

    $("#prg").change( function(){

      selectedprg = $('#prg option:selected').text(); 

      selectedcount = $('#prg option:selected').data('count');

    });

  });

</script>


查看完整回答
反對 回復 2023-05-12
  • 1 回答
  • 0 關注
  • 140 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號