[英]How do I get the input value using it's id in JQuery?
This is the html code: 这是html代码:
<input id="billing:company" name="billing[company]" value = "1" type="text">
and this is the jquery code: 这是jQuery代码:
company = jQuery("#billing:company").val();
the company value is undefined. 公司价值未定义。 How I get with jquery an input value which has in the id a colon " : "
我如何用jquery获取ID中带有冒号“ : ” 的输入值
You can use backslash for meta character such as !"#$%&'()*+,./:;<=>?@[]^`{|}~: 您可以将反斜杠用于元字符,例如!“#$%&'()* +,。/ :; <=>?@ [] ^`{|}〜:
company = jQuery("#billing\\:company").val();
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
ID和NAME令牌必须以字母([A-Za-z])开头,后跟任意数量的字母,数字([0-9]),连字符(“-”),下划线(“ _”) ,冒号(“:”)和句点(“。”)。
So, your declaration of colon in id is perfectly valid. 因此,您在id中的冒号声明是完全有效的。
您可以使用属性选择器来匹配id
:
company = jQuery("input[id='billing:company']").val();
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function() {
var company = jQuery("input[id='billing:company']").val();
$("input[id='billing:company']").trigger('keyup');
alert(company);
$(document).delegate("input[id='billing:company']",'keyup',function(e){
var company = company = jQuery("input[id='billing:company']").val();
alert(company);
});
});
</script>
</head>
<body>
<input id="billing:company" name="billing[company]" value = "1" type="text">
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.