Home >Web Front-end >JS Tutorial >JQuery is a way to get sibling values ​​(for example, if you are in GridView)_jquery

JQuery is a way to get sibling values ​​(for example, if you are in GridView)_jquery

WBOY
WBOYOriginal
2016-05-16 17:55:18989browse
Copy code The code is as follows:









< ;/ItemTemplate>



You want to get the value in the hidden field behind the selected checkbox, as follows:
Copy code The code is as follows:

function SelectReceipt()
{
var checknum = 0;
var customerCode = "";
var type = "";
var url = "";
checknum = $("input:checked").length;
if ( checknum > 1)
{
alert("Only one record can be selected for payment!");
return false;
}
else
{
alert( checknum);
if (checknum == 1)
{
customerCode = $("input:checked").next().attr("value"); //Get through the next() method , if you want to get the next hdCustomerName value, you can .next().next().
//customerName = $("input:checked~#hdCustomerName").val();//IE will report an error when using ID, but firefox will not
type = $("input:checked~.hdStatus") .attr("value");//Or get it by using class,
url = 'PreReceiptDeposit.aspx?customerCode=' customerCode '&departmentType=' type;
}
else
{
url = 'PreReceiptDeposit.aspx?customerCode=' '' '&departmentType=' type;
}
alert(url);
UniversalOpenWindowAndBreak(640, 600, url, 1);
return true;
}
}

jQuery--checkbox select/unselect all
Copy code The code is as follows:






1

2

3

4

Select all/Deselect all




jQuery.attr gets/sets the attribute value of the object, such as:
$("input[name='chk_list']").attr("checked"); //Read all names whose name is 'chk_list' 'The status of the object (whether it is selected)
$("input[name='chk_list']").attr("checked",true); //Set checked to true for all objects named 'chk_list'
Another example:
$("#img_1").attr("src","test.jpg"); //Set the value of src with ID of img_1 to 'test.jpg'
$("#img_1").attr("src"); //Read the src value with ID img_1
The following code is to get the value of the checkbox selected in the above example:
Copy code The code is as follows:



The following is the code traversed using $.each():
Copy the code The code is as follows:


Statement:
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