select自己定義屬性值
阿新 • • 發佈:2017-07-28
bsp size gravity con hang lan func tex lang
3、實現結果
select自己定義屬性值
1、問題背景
下拉框能夠傳遞值和內容,只是有時為了傳值,還須要連帶其它的值也一起傳過來。假設用title屬性。鼠標移到下拉框上方會顯示出來,這樣就會導致被暴露出來。所以,為了安全和傳值方便。能夠利用自己定義屬性。
2、實現源代碼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>自己定義下拉框屬性值</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script type="text/javascript" src="<%=basePath%>/js/jquery-2.2.3.js"></script> <script type="text/javascript"> $(function(){ $("#sel").change(function(){ var sel = $("#sel option:selected").val(); var name = $("#sel option:selected").text(); var child = $("#sel option:selected").attr("child"); alert("下拉框的值:"+sel+"\n"+"下拉框的內容:"+name+"\n"+"下拉框屬性值child:"+child); }); }); </script> </head> <body> <div id="div-select"> <select id="sel" style="width:200px;"> <option value="1" child="2016010101">籃球</option> <option value="2" child="2016010102">足球</option> <option value="3" child="2016010103">鉛球</option> <option value="4" child="2016010104">羽毛球</option> <option value="5" child="2016010105">乒乓球</option> <option value="6" child="2016010106">網球</option> </select> </div> </body> </html>
3、實現結果
select自己定義屬性值