How to get the select value in layui

藏色散人
Release: 2023-01-13 00:40:10
Original
9088 people have browsed it

The method for layui to get the select value: first open the corresponding template code file; then reference the layui plug-in; finally obtain the value of the drop-down box through the "var batch=$("#batch").val();" method Just value.

How to get the select value in layui

The operating environment of this tutorial: Windows 7 system, layui version 2.4, Dell G3 computer. This method is suitable for all brands of computers.

Recommended: "javascript basic tutorial""layUI tutorial"

layui gets the value selected in the select drop-down box:

Quote the layui plug-in to get the value of the drop-down box

How to get the select value in layui

Template:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>增加、修改学校/层次/专业</title>
  <link rel="stylesheet" href="__ADMIN__/common/frame/layui/css/layui.css">
</head>
<body>
<div class="layui-fluid layui-form">
<form class="layui-form" action="" method="post">
<br>
          <div style="padding-left: 100px; padding-bottom: 20px;"><h2>{$rs1.title} >> {$rs.title}</h2></div>
          <div class="layui-form-item">
            <label class="layui-form-label">学费</label>
            <div class="layui-input-block">
              <input type="text" name="price" required  lay-verify="required" class="layui-input" value="{$rs.price}" readonly>
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">批次</label>
            <div class="layui-input-block">
<select name="batch" id="batch" lay-filter="batch" lay-verify="required" lay-search="required">
                   <option value="">请选择批次</option>
                  {volist name="batch_rs" id="batch"}
    <option value="{$batch.id}" {if condition="$rsEdit.batch eq $batch.id"}selected{/if}>{$batch.title}</option>
    {/volist}
</select>  
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button type="button" id="editbatchschooltuition" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            </div>
          </div>
</form>
</div>
<script src="__ADMIN__/common/frame/layui/layui.js"></script>
<script>
layui.use([&#39;form&#39;, &#39;jquery&#39;], function(){
  var form = layui.form
  ,$= layui.$;
  
// var batch=$("#batch").val();
   
form.on(&#39;select&#39;, function(data){
  console.log(data.elem); //得到select原始DOM对象
  console.log(data.value); //得到被选中的值]
  $("#batch").val(data.value)
  console.log(data.othis); //得到美化后的DOM对象
});  
   
  $(&#39;#editbatchschooltuition&#39;).on(&#39;click&#39;, function(){
  var batch=$("#batch").val();
  alert(batch);
layer.ready(function(){ 
  layer.open({
type: 2,
title: &#39;增加&#39;,
maxmin: true,
area: [&#39;750px&#39;, &#39;400px&#39;],
content: &#39;{:url(&#39;main/addschool&#39;)}?id={$id}&price={$rs.price}&batch=&#39;+batch,
//content: &#39;{:url(&#39;main/addschool&#39;)}&#39;,
cancel: function(){ //刷新网页
  }
  });
});
});
  
});
</script>
</body>
</html>
Copy after login

How to get the select value in layui

The above is the detailed content of How to get the select value in layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!