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 operate in windows fromWindows
- JavaScript獲取選中checkbox valueJavaScript
- MVC HtmlHelper 生成 CheckBox,CheckBoxList,RadioButtonListMVCHTML
- solidity的msg.valueSolid
- @Value失效的問題
- Yii2 中 checkboxlist 核取方塊 預設選中
- golang multiple-value xxx in single-value contextGolangContext
- Drupal 如何得到欄位的值?
- [20231103]sqlplus column new_value old_value.txtSQL
- [20230303]sqlplus column new_value old_value.txtSQL
- @ConfigurationProperties和@Value
- 如何拿到註解@ApiModelProperty(value = “單位名稱“, name = “orgName“)中的value值;API
- 用得到的electron開發總結
- jquery遍歷得到的 Map 資料,jQuery
- textarea中的innerHtml,innerText和valueHTML
- Oracle分析函式-first_value()和last_value()Oracle函式AST
- <checkBox>標籤的value屬性的作用
- SQLSERVER中得到執行計劃的方式SQLServer
- WPF ProgressBar show value
- 7.94 FIRST_VALUE
- 7.92 FEATURE_VALUE
- 7.12 ANY_VALUE
- RESTOREkeyttlserialized-value[REPLACE]RESTTLSZed
- Java獲取Object中Value的方法JavaObject
- 不使用@Value的優雅寫法
- 如何用FGA得到繫結變數的值變數
- 如何得到暴雪娛樂公司的工作機會?
- python: invalid value encountered in divide以及invalid value encountered in double_scalars報錯PythonIDE
- 為什麼Math.abs(Integr.MIN_VALUE)==Integer.MIN_VALUE
- Java交換map的key和value值Java
- [20191127]表 full Hash Value的計算.txt
- @AllArgsConstructor與@Value共用的問題解決Struct
- selenium 如何清除 input 框中的 value 值?
- @Value DI注入 的幾種使用方法
- spring mvc中的@RequestMapping value用法小結SpringMVCAPP
- python request 獲取cookies value值的方法PythonCookie
- Smart Value Help 總結
- Harmonic Value Description HDU - 5916