jQuery 取值操作


  • 模板使用:

    https://startbootstrap.com/themes/sb-admin-2/ 使用的 bootstrap 模块 ,上面的这个网站可以下载

  • select 取值

    <select class="com1_bandrate" id="com1_bandrate"  name=""  onchange="show_com1()">   
     <option   value="2400">2400</option>   
     <option   value="115200">115200</option>   
     <option   value="460800">460800</option>   
     </select>
    
    <script type="text/javascript">
     function show_com1(){
     	console.log(($("#com1_bandrate").find("option:selected").val()));
     }
     function show_com2(){
     	console.log(($("#com2_bandrate").find("option:selected").val()));
     }
    
    </script>
    

    select 取值,可以直接使用 $("#id").find("option.selected").val() 进行取值。

  • text 取值

        <input type="text" class="mb-4 form-control form-control-user" id="eth0_ip" placeholder="IP">
        <input type="text" class="mb-4 form-control form-control-user" id="eth0_gateway" placeholder="Gateway">
        <input type="text" class="mb-4 form-control form-control-user" id="eth0_netmask" placeholder="netmask">
         <input type="text" class="mb-4 form-control form-control-user" id="eth0_dns" placeholder="DNS">
    
        <script type="text/javascript">
     function save_func(){
     	console.log(($("#eth0_ip").val()))
     	console.log(($("#eth0_netmask").val()))
     	console.log(($("#eth0_gateway").val()))
     	console.log(($("#eth0_dns").val()))
    
     	console.log(($("#eth1_ip").val()))
     	console.log(($("#eth1_netmask").val()))
     	console.log(($("#eth1_gateway").val()))
     	console.log(($("#eth1_dns").val()))
     }
    
     function eth0_mode(){
     	console.log(($("#eth0_mode_id").find("option:selected").val()));
     	var eth_mode = $("#eth0_mode_id").find("option:selected").val();
     	if (eth_mode == "static")
     	{
     		$("#eth0_ip").removeAttr("readonly");
     		$("#eth0_netmask").removeAttr("readonly");
     		$("#eth0_gateway").removeAttr("readonly");
     		$("#eth0_dns").removeAttr("readonly");
     	}
     	else
     	{
     		$("#eth0_ip").attr("readonly", "readonly");
     		$("#eth0_netmask").attr("readonly", "readonly");
     		$("#eth0_gateway").attr("readonly", "readonly");
     		$("#eth0_dns").attr("readonly", "readonly");
     	}
     }
     function eth1_mode(){
     	console.log(($("#eth1_mode_id").find("option:selected").val()));
     	var eth_mode = $("#eth1_mode_id").find("option:selected").val();
     	if (eth_mode == "static")
     	{
     		$("#eth1_ip").removeAttr("readonly");
     		$("#eth1_netmask").removeAttr("readonly");
     		$("#eth1_gateway").removeAttr("readonly");
     		$("#eth1_dns").removeAttr("readonly");
     	}
     	else
     	{
     		$("#eth1_ip").attr("readonly", "readonly");
     		$("#eth1_netmask").attr("readonly", "readonly");
     		$("#eth1_gateway").attr("readonly", "readonly");
     		$("#eth1_dns").attr("readonly", "readonly");
     	}
    
    
     }
    
    </script>
    
    


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM