在 JS 和 html 中添加关闭选项值

Add off option value in JS and html

我想在我的页面中添加关闭选项值

例如,您进入我的商店页面并选择一个包裹,我想为折扣添加一个选项字段,当您输入 s.txt 上可用的文本时,您会收到折扣优惠。

例如,您输入 Whosebug 代码并在 s.txt:

Whosebug--20

然后价格会降低%20并显示。

我的源代码如下。

JavaScript:

$("#payBtn").click(function() {
  $("#count").html($("#member").val());
  var price = $("#member").val();
  price = price * 5;
  location.href = 'https://zarinp.al/levicoder/' + price;
    }); 
$("#name").keyup(function() {
  $("#payerName").html($("#name").val());
});
$("#channelInput").keyup(function() {
  $("#channel").html($("#channelInput").val());
});
$("#discount").keyup(function() {
  $("#disdis").html($("#discount").val());
});
$("#member").click(function() {
  $("#count").html($("#member").val());
  var price = $("#member").val();
  price = price * 5;
  $("#amount").html(price);
});

Html:

<div class="box shadow_box purchase_cm_box" >
        <h4>Order</h4>
        <hr>
        <input type="text" class="form-control" id="name" placeholder="Your name"><br>
        <input type="text" class="form-control" id="channelInput" placeholder="Your Id"><br>
        <input type="text" class="form-control" id="discount" placeholder="discount code"><br>
        <div class="form-group">
         <select class="form-control" id="member">
           <option value="9000">9000 Value</option>
<option value="2000">2000 Value</option>



         </select>
         <br>
        </div>
      </div>

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 pull-left" id="leftmenu">
      <div class="box shadow_box purchase_cm_box" >
          <h4>Factor</h4>
        <hr>
        Your Name : <label id="payerName">don't entered</label><br>
        Your id : <label id="channel"></label><br>
        discount code : <label id="disdis"></label><br>
        Pay Count
        <label id="amount">7,000</label>
         $
        <br><br>
                <button class="getBtn" id="payBtn">Pay</button><br>

        <p id="payStatus"></p>
      </div>
  </div>

我尽量不正式回答这个问题,因为我不确定 LeVi 需要什么。但是由于我们在评论中的对话,我被要求提供代码。

以下是我对 LeVi 要求的最佳猜测:

let inputCode = "Whosebug"; 
let savedCode = "Whosebug--20"; // derived from file s.txt

let splitSavedCode = savedCode.split('--'); // this will return ['Whosebug', '20'] 

if( inputCode == splitSavedCode[0] ) { 
  // edited after further discussion in comments
  let discountPercentage = splitSavedCode[1] / 100;
  let discountAmount = price * discountPercentage;
  $('#discount').val(discountAmount);
}