Javascript得到CheckBoxList的Value
主要思路就是為ListItem加一個"checkValue"屬性,前臺通過javascript找到。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxListValue.aspx.cs" Inherits="test_CheckBoxListValue" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Javascript得到CheckBoxList的Valuetitle>
<script type="text/javascript" src="../js/jquery-1.3.2.min.js">script>
<script type="text/javascript">
//把選中的值寫入hiddenfield
function f(){
var total = $("#chkBox input[@type=checkbox]:checked").size();
var checkValues = '';
$("#chkBox input[@type=checkbox]:checked").each(function(){
checkValues += $(this).parent().attr("checkValue") + ",";
});
alert("選中了" + total + "個" + "\n" + "值:" + checkValues.substring(0,checkValues.length-1));
}
script>
head>
<body>
<form id="form1" runat="server">
<div>
主要思路就是為ListItem加一個"checkValue"屬性,前臺通過javascript找到。
div>
<div>
<input type="button" onclick="f();" value="取值" />
<asp:CheckBoxList ID="chkBox" runat="server">
asp:CheckBoxList>
div>
form>
body>
html>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxListValue.aspx.cs" Inherits="test_CheckBoxListValue" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Javascript得到CheckBoxList的Valuetitle>
<script type="text/javascript" src="../js/jquery-1.3.2.min.js">script>
<script type="text/javascript">
//把選中的值寫入hiddenfield
function f(){
var total = $("#chkBox input[@type=checkbox]:checked").size();
var checkValues = '';
$("#chkBox input[@type=checkbox]:checked").each(function(){
checkValues += $(this).parent().attr("checkValue") + ",";
});
alert("選中了" + total + "個" + "\n" + "值:" + checkValues.substring(0,checkValues.length-1));
}
script>
head>
<body>
<form id="form1" runat="server">
<div>
主要思路就是為ListItem加一個"checkValue"屬性,前臺通過javascript找到。
div>
<div>
<input type="button" onclick="f();" value="取值" />
<asp:CheckBoxList ID="chkBox" runat="server">
asp:CheckBoxList>
div>
form>
body>
html>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test_CheckBoxListValue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Bind();
}
private void Bind()
{
ListItem li1 = new ListItem("1", "1");
li1.Attributes.Add("checkValue", "1");
chkBox.Items.Add(li1);
ListItem li2 = new ListItem("2", "2");
li2.Attributes.Add("checkValue", "2");
chkBox.Items.Add(li2);
}
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test_CheckBoxListValue : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Bind();
}
private void Bind()
{
ListItem li1 = new ListItem("1", "1");
li1.Attributes.Add("checkValue", "1");
chkBox.Items.Add(li1);
ListItem li2 = new ListItem("2", "2");
li2.Attributes.Add("checkValue", "2");
chkBox.Items.Add(li2);
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-617527/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- JavaScript select valueJavaScript
- 實現checkboxlist的全選
- 今天知道了在js中怎麼得到的value值JS
- checkboxList operate in windows fromWindows
- javascript獲取所有表單元素的value值JavaScript
- JavaScript獲取選中checkbox valueJavaScript
- CheckBoxList擴充套件方法程式碼套件
- javascript中關於value的一個小知識點(value既是屬性也是變數)JavaScript變數
- JavaScript select選中項的value值和文字內容JavaScript
- MVC HtmlHelper 生成 CheckBox,CheckBoxList,RadioButtonListMVCHTML
- javascript獲取select下拉選單框的value和text值JavaScript
- javascript如何獲取當前選中的option項的文字和value值JavaScript
- JavaScript判斷表單元素value值是否被修改過JavaScript
- 得到promisePromise
- 從C++的Return Value Optimization (RVO)到C#的value type (轉)C++C#
- 得到框架中物件的值框架物件
- LOW_VALUE、HIGH_VALUE、ENDPOINT_VALUE轉換--UTL_RAW、DBMS_STATS.CONVERT_RAW_VALUE
- solidity的msg.valueSolid
- 分析函式——FIRST_VALUE()和LAST_VALUE()函式AST
- 物件啟用用得到的Program物件
- 得到VIEW的定義語法View
- new_value
- vb中從域名得到IP及從IP得到域名 (轉)
- Oracle分析函式-first_value()和last_value()Oracle函式AST
- textarea中的innerHtml,innerText和valueHTML
- 函式引數的 Default value函式
- 得到檔案大小
- 解析域名得到IP
- webservice得到自身IPWeb
- 如何拿到註解@ApiModelProperty(value = “單位名稱“, name = “orgName“)中的value值;API
- 用得到的electron開發總結
- jquery遍歷得到的 Map 資料,jQuery
- py指令碼得到Python的版本指令碼Python
- for迴圈得到的隨機數相同隨機
- PHPWIND得到管理員密碼的方法PHP密碼
- 得到固定字元位置的函式 (轉)字元函式
- 如何將列中的low_value和high_value轉換為實際的值
- jQuery [attribute*=value]jQuery