[英]How can I get the value of a textbox using jquery class selector?
how can I get the value of a textbox using jquery class selector? 如何使用jquery类选择器获取文本框的值?
My html looks like this: 我的html看起来像这样:
<input class="TextBoxTime" id="time2" name="time2" type="text" value="01:30 AM" />
I want to get the value without using the id because I'm creating the id during run time. 我想在不使用ID的情况下获取值,因为我是在运行时创建ID的。 I'm trying to do something like this:
我正在尝试做这样的事情:
var theClassTime = $("input.TextBoxDate");
$("#saveBtn").click(function () {
$("input[name='selectedCourses']").each(function (i) {
if (this.checked) {
var theTimes = theClassTime.find('input:eq('+ i +')').prop('selected', true).val();
alert(theTimes);
}
});
});
How can I get to the value of this input element without using it's id? 如何在不使用id的情况下获取此输入元素的值?
Live demo : http://jsbin.com/mibid 现场演示: http : //jsbin.com/mibid
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<input class="my" type="text" value="a" />
<input class="my" type="text" value="b" />
<input class="my" type="text" value="c" />
<input class="my" type="text" value="d" />
<input class="my" type="text" value="e" />
<button onclick="show()">Click me</button>
</body>
</html>
<script>
function show(){
$(".my").each(function() {
var val = $(this).val();
alert(val);
});
}
</script>
Following are multiple ways to access give item. 以下是访问礼品的多种方式。
.class $(".intro") //All elements with class="intro"
.class,.class $(".intro,.demo")// All elements with the class "intro" or "demo"
element $("p") // All <p> elements
:first $("p:first") The first <p> element
:last $("p:last") The last <p> element
:even $("tr:even") All even <tr> elements
:odd $("tr:odd") All odd <tr> elements
To get All input elements with type="text" :text $(":text")
获取所有类型为type =“ text”的输入元素
:text $(":text")
to get the values just use val() from that control. 要获取值,只需使用该控件中的val()即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.